home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6861 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  8.1 KB

  1. Path: vb.franken.de!volker
  2. From: volker@vb.franken.de (Volker Barthelmann)
  3. Subject: Re: 680X0 -> PPC translator?
  4. Newsgroups: comp.sys.amiga.programmer
  5. References: <315800D7.1854@sapiens.com> <volker.0g32@vb.franken.de> <315C198B.49C2@netvision.net.il> <volker.0g5w@vb.franken.de> <3162980C.2003@netvision.net.il>
  6. X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
  7. Message-ID: <volker.0g8h@vb.franken.de>
  8. Date: 4 Apr 96 00:05:24 MET
  9. Organization: home
  10.  
  11. Jack (avilev@netvision.net.il) wrote:
  12.  
  13. : you don't have to understand what a program does in order to convert
  14. : its code from one instruction set to another. all you look for are
  15. : specific things and provided you know the op-codes of the 2 processors
  16. : there should be no problem whatsoever.
  17.  
  18. Well, that's just an unfounded claim. There will be problems and anyone
  19. who really thought about such things knows that.
  20.  
  21. : not necessarily, all static code is inside the program already, all there's
  22.                                                                   ^^^^^^^^^^^
  23. : to do is follow the logic of the program keeping track of what memory areas
  24.   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  25. : are being used AND how. now don't be confused again, you don't need actual
  26.   ^^^^^^^^^^^^^^^^^^^^^^
  27.  
  28. = completely understand the program = absolutely impossible.
  29.  
  30. You can't be serious!
  31.  
  32. : > Well, please define those 'well defined' series of actions.
  33. :
  34. : as soon as i find out the pointer is a CODE pointer i do the following:
  35. :
  36. : 1) trace back in the program where that pointer was assigned.
  37. : 2) decide whether the area it's pointing to is static (meaning within one of
  38. : the program's segments) or a dynamic one.
  39.  
  40. Which is not possible once an external function is called.
  41.  
  42. : 3) if (2) == dynamic then calculate 'source' code size and look it up withing
  43. : one of the arguments just before the call/jmp is made. the argument will
  44.  
  45. What makes You think You will find the source code size as argument to
  46. any function call??
  47.  
  48. : be an immediate or stored in some variable, the point is it's INSIDE the
  49. : one of the program's segments and it's a REAL VALUE.
  50. : change the size according to the translated code size. (i'm assuming the code
  51. : has already been chewed up and spitted out)
  52.  
  53. Won't work if the size has to meet certain conditions.
  54.  
  55. : 4) is (2) == static then increase the size of the hunk it's located in.
  56. : 5) find the last write loop just before the call was made and change the counter's
  57. : end value condition, changing the move instruction to move bytes.
  58.  
  59. How the hell do You recognize 'the last write loop'?
  60. Can You give formal specification of how to recognize a write loop at all?
  61.  
  62. : 6) go on happily to other parts of the program.
  63. :
  64. : HUH, i wrote it, lets see your response to that Volker. flame me good this
  65. : time, ok? :-)
  66.  
  67. Well, I gave some reasons why it doesn't work. If You want a flame: It's
  68. bullshit. :-)
  69.  
  70. : > What do You do if a program does an OpenLibrary("some_custom.library",foo);
  71. : > and a jsr -some_strange_offset_I've_never_seen_before(a6)?
  72. : > This function could call AllocMem. You don't even know what parameters it
  73. : > takes etc.
  74. :
  75. : AHHHHH, that is where you're wrong (again, teehee), here's that phrase again,
  76. : 'keep track', i know i know, this term is without a doubt overused in my articles,
  77. : but hey, this is WAR, any means can be used to achieve the target, PPC dominance.
  78.  
  79. ??
  80.  
  81. : now, if you save your stack status before every call is made, you can know which
  82. : parameters on the stack belong to that function. for example if the stack
  83. : contained: A,B,C before and now D,E,F are pushed and then there's a call to
  84. : some routine then you know D,E,F are its arguments don't you.
  85. : bear in mind that the external library is PPC translated already, any
  86.  
  87. But You don't know anything about this function. Neither what arguments it
  88. takes nor what it does.
  89.  
  90. : code-modification tricks it does won't need any changes.
  91. : ofcourse, __regarg functions (in C) don't use the stack for all parameters
  92. : i know, and some assembly programs like to do register passing of arguments
  93. : well, then in that case it's truely more diffilcult but not impossible.
  94. : if the call is to some C RTL function, then no sweat, i can go directly to
  95.  
  96. What's a C RTL function?
  97.  
  98. : the function and actually see how it uses the register in its code and
  99. : dicsern the call prototype and make the necessary adjustments. if it's a
  100. : DOS library things might get a little complicated, but could be solve by
  101. : some educated guess as to what needs to be changed.
  102.  
  103. Educated guess? Oh well...
  104.  
  105. : > If You write a program that only reads a normal assembly source file that
  106. : > is known to copy some piece of code somewhere and Your program can change the
  107. : > source to copy one byte more, I'll believe You (and call You god, if You want).
  108. :
  109. : well, if i'll have the time and energy i will, but 1st i have to write the analyser
  110. : program to do that. that might take some time.
  111.  
  112. Infinite time, I guess?
  113.  
  114. : > Yes, You have. E.g. the allocator could assume that all requests are multiples
  115. : > of 1024 and rely on that. Now the original code may have been a multiple
  116. : > of 1024, but the PPC-code probably isn't. So when You pass the PPC-code-size
  117. : > to the allocator it will go nuts.
  118. :
  119. : so what??? the area will later be used in some loop copying the code, right?! it'll
  120. : have to use actuall byte/word count to do that. you look into the allocation 'prototype'
  121. : and try to find out that value. if you can't find it, then you're probably right, it
  122. : uses some multiple of some size, in that case the minimum multiple it would have to be
  123.  
  124. Well, of course the allocator could need other requirements, too.
  125.  
  126. : is calculated by unit = actual_source_size/num_units_requested;
  127. : then you use that unit size in the calculation of the PPC code size and you're done.
  128. : of course there'll be some memory wastes but who cares about that.
  129.  
  130. Care to explain how You are going to determine what unit size the allocator
  131. needs?
  132.  
  133. : > Still I claim You can't even reliably decide what is code and what is data.
  134. : > Even if self-modifying code is forbidden.
  135. :
  136. : that's absurd, if a human can follow an assembly source code and can know which
  137. : parts are code and which ones are data so can a fucken algorithm.
  138.  
  139. I doubt that a human can do it reliably and I'm not sure  an algorithm can
  140. do everything a human can.
  141.  
  142. : > Assume a program that has some kind of keyfiles. It has n areas that could
  143. : > be code or data and Your algorithm has to decide that.
  144. : > Assume that the addresses of those areas are in an array adr[n].
  145. : > Now the program call the system function Open("env:keyfile",MODE_OLDFILE),
  146. : > reads all longwords from the file, adds them up and calls adr[sum%n].
  147. : > To know which areas could be called You would have to know all valid
  148. : > keyfiles. Of course no algorithm knows them and therefore can't decide what
  149. : > is code. qed.
  150. :
  151. : if that's your example of a real value, think AGAIN. this can easily be solved
  152. : by going through all the various hunks of the program trying to find CODE sections.
  153. : when you find a code instruction that 'makes sense' mark the section's entry point.
  154. : if somebody else calls it you know it's code for sure, then you translate it.
  155. : you go through all such code sections and understand when and where they're being
  156. : used making sure to translate only code sections actually being used. if a sequence
  157. : of data words reveals code it might actually not be code so you have to defer the
  158. : translation until you're sure about it.
  159.  
  160. That's the point! And in this case You can't be sure before runtime. So
  161. a static translator is impossible. That's what I said and proved.
  162.  
  163. : chances are it's code, if more than 2-3
  164. : instructions exists in sequence that probably is code and can thus be translated.
  165.  
  166. Programming by Monte Carlo methods?
  167.  
  168. : if it was just random data, then nothing happened, we just randomised it again.
  169. : better think harder, now flame me.
  170.  
  171. Of course it may have been not-random data. And of course by interpreting it
  172. as code You might find a 'jmp xyz' in this random data. So You have to
  173. translate from xyz, too...
  174.  
  175. I think I'll stop this discussion now. Although it started some time before
  176. April 1st, I can't help feeling like an April fool...
  177.  
  178. Volker
  179.  
  180.