<div dir="ltr">Hi Bastian,<div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 19, 2017 at 5:30 PM, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Bastian,<div><br></div><div>    welcome!</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 19, 2017 at 2:09 AM, Kruck, Bastian <span dir="ltr"><<a href="mailto:Bastian.Kruck@student.hpi.de" target="_blank">Bastian.Kruck@student.hpi.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <br>



<div style="word-wrap:break-word">
<div>
<div>Hi Folks,<br>
<div>
<div style="word-wrap:break-word">
<div>
<div>
<div>
<div style="word-wrap:break-word">
<div style="word-wrap:break-word">
<br>
<div>Do you have a moment to give me a hint on the following error?<br>
<div><br>
I’m currently trying to get the result of the cogged version of SmallInteger>>#+ by simulating it in VMMaker. So I initialise the simulator, lookup the method in the loaded image and finally start Bochs by calling simulator activateCoggedNewMet<wbr>hod: false.<br>
<br>
Now I can see the primitiveSingleStepInMemoryMin<wbr>imumAddressReadWrite failing when trying trying to return to esp=16r11 which is my receiver. So it seems my stack gets corrupted at some point. So I start tracing what the processor is doing:<br>
<br>
- starts at ceEnterCogCodePopReceiverRe<wbr>g (pc=16r1128)<br></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>If you're using StackToRegisterMappingCogit then ceEnterCogCodePopReceiverReg shouldn't be used to activate SmallInteger>>#+.  StackToRegisterMappingCogit <wbr>uses a register-based calling convention (see <wbr>StackToRegisterMappingCogit class>>#callingConvention).  With the V3 memory manager 0 and 1 arg sends are passed in registers and with Spur 0, 1 & 2 arg sends are passed in registers.  Higher rarities are passed on the stack.  So the VM needs to enter machine code via the <wbr>callCogCodePopReceiverArg0Regs et al enilopmarts.  What I don't understand is why this isn't happening anyway; activateCoggedNewMethod invokes <wbr>callRegisterArgCogMethod:at:<wbr>receiver: to do this.  Perhaps the simulator isn't initialized correctly?</div><div><br></div><div>Ah, I see.  There's an assumption that activateCoggedNewMethod will only enter frameless methods via callRegisterArgCogMethod:at:<wbr>receiver: (methods the StackToRegisterMappingCogit optimizes to run without building a frame).  If the method builds a frame (which SmallInteger>>#+ will if it fails) then activateCoggedNewMethod enters after frame build.  It can always call the Interpreter's version of the primitive if the method has a primitive, avoiding entering machine code for primitives, since they almost always succeed.</div><div><br></div><div>This doesn't work for you.  I suggest you write a variation on activateCoggedNewMethod that uses callRegisterArgCogMethod:at:<wbr>receiver: for any method with numArgs <= numRegArgs.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><div style="word-wrap:break-word"><div><div><div><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div><div>
- then it enters the compiled SmallInteger>>#+ (pc= 16r1462, the position with HasByteCodePC)<br>
- then it enters ceSuperSend1Args (pc=16r570)<br>
- and runs further up to the return (at pc=16r5aa) where it will have the esp=16r11<br>
<br>
<div>Can you give me a hint on what’s happening here? I put the notes while tracing into a txt file that you can find attached. If you want to try it out yourself, I uploaded the image and the VM version here <a href="https://www.dropbox.com/sh/6sevutlcpx3of42/AAA9ScgmvK5IeLaCxE6yWJ8Ua?dl=0" target="_blank">https://www.dropbox.com/s<wbr>h/6sevutlcpx3of42/AAA9ScgmvK5I<wbr>eLaCxE6yWJ8Ua?dl=0</a></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div></div></div></blockquote><div><br></div><div>Forgive me, I didn't look carefully enough yesterday.  The method that you need is already there.  Try</div><div><br></div><div>executeCogMethod:fromUnlinkedSendWithReceiver:</div><div><br></div><div>This method assumes the receiver, arguments and return address are on the Smalltalk stack and then enters the method's machine code from the unchecked entry point. It should do exactly what you want.</div><div><br></div><div>If you put a fake return address on the stack then Bochs will raise an exception as it tries to return and you'll be able to collect the result in an exception handler.</div><div><br></div><div>HTH</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div style="word-wrap:break-word">The Background: I’m currently working on my master thesis on Multi-Level Debugging where I’m building a debugger that is supposed to detect erroneous code transformations by redundantly executing the Slang, the running vm, the fallback code and
 also the JIT-compiled fallbacks.<br></div></div></div></div></blockquote><div><br></div><div>Cool.  It's great to have another person diving into the guts of the VM.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><div style="word-wrap:break-word"><div><div><div><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div><div><div>
<div>Thank you so much!<br></div>
<div>Basti</div>
<div><br>
</div>
<div></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<br></blockquote></div><span class="gmail-HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="gmail-m_2051798923881585506gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</font></span></div></div>
</blockquote></div><br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>