Skip to contentSkip to conversation

Question about gen_jmp_tb

Qemu-devel Jack Biggs 3 participants 6 messages Jun 2, 2014 2 messages not in the archive

lore
Share & tools
lore

Jack Biggs

author
#2 lore raw
In reply to a message not in the archive

Hi Richard, thanks for your help.

Which instruction, then, I should add my gen_helper to in order for it to be called at the end of each basic block, as I've previously stated? Is there a way I can generically have this change apply to every target?

Jack

Quoted 16 lines · Richard Henderson
Quoted 7 lines · Jack Biggs

Hi all,

I'm trying to add some arbitrary code to the end of each translation block, and I wanted to confirm my suspicion that each translation block ends in a jmp instruction, and that each translation block ends (or jumps to another TB) with the call to gen_jmp_tb. My guest is i386, but if this is architecture-specific I'd like to know more about per-target semantics.

No, not every tb ends with gen_jmp_tb. Indeed, only those for which we have an immediate address end that way. Plenty of tb's end with indirect branches, or for a variety of other reasons.

Certainly gen_jmp_tb is specific to the i386 translator.

r~

#3 lore raw
Quoted 15 lines · Jack Biggs

Hi Richard, thanks for your help.

Which instruction, then, I should add my gen_helper to in order for it to be called at the end of each basic block, as I've previously stated? Is there a way I can generically have this change apply to every target?

Jack

Quoted 6 lines · Richard Henderson
Quoted 5 lines · Jack Biggs

Hi all,

I'm trying to add some arbitrary code to the end of each translation block, and I wanted to confirm my suspicion that each translation block ends in a jmp

When you say arbitrary code what do you mean? Are you wanting to put backend specific code there or a common post-amble of tcg ops?

Can you give a bit more detail about your use case?

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

instruction, and that each translation block ends (or jumps to another TB) with the call to gen_jmp_tb. My guest is i386, but if this is architecture-specific I'd like to know more about per-target semantics.

No, not every tb ends with gen_jmp_tb. Indeed, only those for which we have an immediate address end that way. Plenty of tb's end with indirect branches, or for a variety of other reasons.

Certainly gen_jmp_tb is specific to the i386 translator.

r~

Signature · 1 line
Alex Bennée
author
#4 lore raw
Quoted 1 line

When you say arbitrary code what do you mean? Are you wanting to put backend specific code there or a common post-amble of tcg ops? Can you give a bit more detail about your use case?

I'm trying to add a clock-synchronization library so that I can have two (or more) instances of QEMU run in a synchronized (deterministic) fashion. The "arbitrary code" is more or less a function call (i.e., callq) instruction to a function that uses shared semaphores to block execution.

Jack

#5 lore raw
Quoted 9 lines · Jack Biggs
Quoted 3 lines

When you say arbitrary code what do you mean? Are you wanting to put backend specific code there or a common post-amble of tcg ops? Can you give a bit more detail about your use case?

I'm trying to add a clock-synchronization library so that I can have two (or more) instances of QEMU run in a synchronized (deterministic) fashion. The "arbitrary code" is more or less a function call (i.e., callq) instruction to a function that uses shared semaphores to block execution.

Bear in mind that we can also exit a TB via taking an unexpected exception [usually a load/store which faults], in which case we'll effectively longjump out of the middle of it.

If you can rearrange your design to only require your hooks to be called at the *start* of a TB, not the end, that is much easier -- the existing icount machinery does that already.

thanks
-- PMM

author
#6 lore raw

Hi Peter,

This is not a problem for now, the main reason we wanted to have this at the end is to potentially trace load / stores in the future. How would you recommend integrating this into icount? Just wanting to make sure I don't run into anything unexpected.

Regards,

Jack

Quoted 1 line · Peter Maydell

If you can rearrange your design to only require your hooks to be called at the *start* of a TB, not the end, that is much easier -- the existing icount machinery does that already. thanks -- PMM

#7 lore raw
Quoted 4 lines · Jack Biggs

This is not a problem for now, the main reason we wanted to have this at the end is to potentially trace load / stores in the future. How would you recommend integrating this into icount? Just wanting to make sure I don't run into anything unexpected.

The icount hooks are in gen-icount.h.

thanks
-- PMM