XPost: comp.lang.forth   
   From: albert@nospicedham.cherry   
      
   In article <18tjcqhoqstpp.1b20okrmpfmz8$.dlg@40tude.net>,   
   JJ wrote:   
   >On 07 Mar 2020 10:39:51 GMT, none wrote:   
   >> I have an 64 bits Forth system, and I can add a program that   
   >> executes a single instruction, like so   
   >> "   
   >> WANT ASSEMBLERi86   
   >>   
   >> CODE PIET   
   >> MOVI|X, AX| 2 IL,   
   >> NEXT,   
   >> END-CODE   
   >> "   
   >>   
   >> And execute it like so   
   >> PIET OK   
   >>   
   >> This program does nothing. It fills EAX with 2 which is inconsequential   
   >> because EAX is a free register. [Only SP BP and SI are used in the   
   >> virtual system.]   
   >> Now let us prefix the instruction, such that the alternate register set   
   >> is used. This should be likewise inconsequential.   
   >>   
   >> CODE PIET1   
   >> $49 C, \ That is the way to do that in Forth   
   >> MOVI|X, AX| 2 IL,   
   >> NEXT,   
   >> END-CODE   
   >>   
   >> Now PIET1 leads to a segfault.   
   >> I've no clue what could cause this.   
   >>   
   >> I have been working with those prefixes for ages.   
   >> My ciasdis has disassembled and reassembled a 64 bit elf program   
   >> without problems.   
   >> [ This is in the context of an optimiser, I seem to have used   
   >> this R1 in optimised programs, that work. ]   
   >>   
   >> Groetjes Albert   
   >   
   >Inserting that 0x49 opcode would change the instruction functionality from:   
   >   
   > mov eax, <32-bit immediate value>   
   >   
   >To:   
   >   
   > mov r8, <64-bit immediate value>   
   >   
   >As well as changing the instruction length from 5 bytes, to 10 bytes.   
   >   
   >So, the 4 bytes following the `mov eax, ` instruction are the upper   
   >32-bits of the `mov r8, `.   
   >   
   >If the generated code is like this:   
   >   
   > 49 db 49h   
   > B8 02 00 00 00 mov eax, 2   
   > C3 ret   
   > 90 nop   
   > 90 nop   
   > 90 nop   
   >   
   >It will be interpreted as:   
   >   
   > 49 B8 02 00 00 00 C3 90 90 90 mov r8, 909090C300000002   
   >   
   >Where the following instruction is no longer a `RET` instruction. So, it   
   >won't immediately return to the caller. When executed, the result would be   
   >unpredictable and eventually ends up crashing the program, because we don't   
   >know what data follows that instruction.   
      
   Thank you. This is the correct answer. I did an experiment putting   
   a lot of nops after the MOVI. Sure enough, I got a long constant with   
   lots of 90 and no crashes.   
      
   One thing to add though: this behaviour is different than the   
   situation where there is an operation with immediate data.   
   Then the immediate data is always 32 bit and sign extended.   
   I missed the difference.   
      
   Groetjes Albert   
   >   
   --   
   This is the first day of the end of your life.   
   It may not kill you, but it does make your weaker.   
   If you can't beat them, too bad.   
   albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|