lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Lightning] Code patching, context switching


From: Paolo Bonzini
Subject: Re: [Lightning] Code patching, context switching
Date: Wed, 20 Feb 2008 07:56:41 +0100
User-agent: Thunderbird 2.0.0.9 (Macintosh/20071031)

I want to use Lightning for user-level context switching, similar to
GNU Pth.

Why not use makecontext/swapcontext? (which is what Pth uses except for signal handling).

 1. There is currently no Lightning equivalent to the x86's 'pusha'
instruction [1], correct?
 2. I assume then that I would have to save all registers by iterating
over JIT_R/V/FPR manually while generating this code. Are there any
registers or other state that aren't accessible via Lightning that
might impact context switching?

Yes. On the PowerPC, the argument registers are *not* available to the user, because they are caller-save while GNU lightning always provides the illusion that they are callee-save.

/* from and to are buffers sufficiently large to hold the register file */
static void ctxt_switch(char *from, char *to) {
  from = from;
  to = to;
  from = from;
  to = to;
  ...
}

I can then take the address of ctxt_switch and pass it to Lightning as
the code buffer and patch the contents of ctxt_switch to perform an
actual context switch. The other alternative is to simply patch in a
direct jump at &ctxt_switch into my code generated elsewhere. Any
other thoughts or recommendations?

I think that the code is readonly on all the platforms I ever looked at that have an MMU. You would have to use mprotect first; then I think that patching a direct jump is fast enough.

However, beware the compiler. It will remove all those pseudo-NOP statements that (it looks like this, at least) you placed to make ctxt_switch big enough. It might also inline ctxt_switch, which would screw things up a lot. I would just make ctxt_switch a function pointer.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]