home *** CD-ROM | disk | FTP | other *** search
- Path: vb.franken.de!volker
- From: volker@vb.franken.de (Volker Barthelmann)
- Subject: Re: 680X0 -> PPC translator?
- Newsgroups: comp.sys.amiga.programmer
- 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>
- X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
- Message-ID: <volker.0g8h@vb.franken.de>
- Date: 4 Apr 96 00:05:24 MET
- Organization: home
-
- Jack (avilev@netvision.net.il) wrote:
-
- : you don't have to understand what a program does in order to convert
- : its code from one instruction set to another. all you look for are
- : specific things and provided you know the op-codes of the 2 processors
- : there should be no problem whatsoever.
-
- Well, that's just an unfounded claim. There will be problems and anyone
- who really thought about such things knows that.
-
- : not necessarily, all static code is inside the program already, all there's
- ^^^^^^^^^^^
- : to do is follow the logic of the program keeping track of what memory areas
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- : are being used AND how. now don't be confused again, you don't need actual
- ^^^^^^^^^^^^^^^^^^^^^^
-
- = completely understand the program = absolutely impossible.
-
- You can't be serious!
-
- : > Well, please define those 'well defined' series of actions.
- :
- : as soon as i find out the pointer is a CODE pointer i do the following:
- :
- : 1) trace back in the program where that pointer was assigned.
- : 2) decide whether the area it's pointing to is static (meaning within one of
- : the program's segments) or a dynamic one.
-
- Which is not possible once an external function is called.
-
- : 3) if (2) == dynamic then calculate 'source' code size and look it up withing
- : one of the arguments just before the call/jmp is made. the argument will
-
- What makes You think You will find the source code size as argument to
- any function call??
-
- : be an immediate or stored in some variable, the point is it's INSIDE the
- : one of the program's segments and it's a REAL VALUE.
- : change the size according to the translated code size. (i'm assuming the code
- : has already been chewed up and spitted out)
-
- Won't work if the size has to meet certain conditions.
-
- : 4) is (2) == static then increase the size of the hunk it's located in.
- : 5) find the last write loop just before the call was made and change the counter's
- : end value condition, changing the move instruction to move bytes.
-
- How the hell do You recognize 'the last write loop'?
- Can You give formal specification of how to recognize a write loop at all?
-
- : 6) go on happily to other parts of the program.
- :
- : HUH, i wrote it, lets see your response to that Volker. flame me good this
- : time, ok? :-)
-
- Well, I gave some reasons why it doesn't work. If You want a flame: It's
- bullshit. :-)
-
- : > What do You do if a program does an OpenLibrary("some_custom.library",foo);
- : > and a jsr -some_strange_offset_I've_never_seen_before(a6)?
- : > This function could call AllocMem. You don't even know what parameters it
- : > takes etc.
- :
- : AHHHHH, that is where you're wrong (again, teehee), here's that phrase again,
- : 'keep track', i know i know, this term is without a doubt overused in my articles,
- : but hey, this is WAR, any means can be used to achieve the target, PPC dominance.
-
- ??
-
- : now, if you save your stack status before every call is made, you can know which
- : parameters on the stack belong to that function. for example if the stack
- : contained: A,B,C before and now D,E,F are pushed and then there's a call to
- : some routine then you know D,E,F are its arguments don't you.
- : bear in mind that the external library is PPC translated already, any
-
- But You don't know anything about this function. Neither what arguments it
- takes nor what it does.
-
- : code-modification tricks it does won't need any changes.
- : ofcourse, __regarg functions (in C) don't use the stack for all parameters
- : i know, and some assembly programs like to do register passing of arguments
- : well, then in that case it's truely more diffilcult but not impossible.
- : if the call is to some C RTL function, then no sweat, i can go directly to
-
- What's a C RTL function?
-
- : the function and actually see how it uses the register in its code and
- : dicsern the call prototype and make the necessary adjustments. if it's a
- : DOS library things might get a little complicated, but could be solve by
- : some educated guess as to what needs to be changed.
-
- Educated guess? Oh well...
-
- : > If You write a program that only reads a normal assembly source file that
- : > is known to copy some piece of code somewhere and Your program can change the
- : > source to copy one byte more, I'll believe You (and call You god, if You want).
- :
- : well, if i'll have the time and energy i will, but 1st i have to write the analyser
- : program to do that. that might take some time.
-
- Infinite time, I guess?
-
- : > Yes, You have. E.g. the allocator could assume that all requests are multiples
- : > of 1024 and rely on that. Now the original code may have been a multiple
- : > of 1024, but the PPC-code probably isn't. So when You pass the PPC-code-size
- : > to the allocator it will go nuts.
- :
- : so what??? the area will later be used in some loop copying the code, right?! it'll
- : have to use actuall byte/word count to do that. you look into the allocation 'prototype'
- : and try to find out that value. if you can't find it, then you're probably right, it
- : uses some multiple of some size, in that case the minimum multiple it would have to be
-
- Well, of course the allocator could need other requirements, too.
-
- : is calculated by unit = actual_source_size/num_units_requested;
- : then you use that unit size in the calculation of the PPC code size and you're done.
- : of course there'll be some memory wastes but who cares about that.
-
- Care to explain how You are going to determine what unit size the allocator
- needs?
-
- : > Still I claim You can't even reliably decide what is code and what is data.
- : > Even if self-modifying code is forbidden.
- :
- : that's absurd, if a human can follow an assembly source code and can know which
- : parts are code and which ones are data so can a fucken algorithm.
-
- I doubt that a human can do it reliably and I'm not sure an algorithm can
- do everything a human can.
-
- : > Assume a program that has some kind of keyfiles. It has n areas that could
- : > be code or data and Your algorithm has to decide that.
- : > Assume that the addresses of those areas are in an array adr[n].
- : > Now the program call the system function Open("env:keyfile",MODE_OLDFILE),
- : > reads all longwords from the file, adds them up and calls adr[sum%n].
- : > To know which areas could be called You would have to know all valid
- : > keyfiles. Of course no algorithm knows them and therefore can't decide what
- : > is code. qed.
- :
- : if that's your example of a real value, think AGAIN. this can easily be solved
- : by going through all the various hunks of the program trying to find CODE sections.
- : when you find a code instruction that 'makes sense' mark the section's entry point.
- : if somebody else calls it you know it's code for sure, then you translate it.
- : you go through all such code sections and understand when and where they're being
- : used making sure to translate only code sections actually being used. if a sequence
- : of data words reveals code it might actually not be code so you have to defer the
- : translation until you're sure about it.
-
- That's the point! And in this case You can't be sure before runtime. So
- a static translator is impossible. That's what I said and proved.
-
- : chances are it's code, if more than 2-3
- : instructions exists in sequence that probably is code and can thus be translated.
-
- Programming by Monte Carlo methods?
-
- : if it was just random data, then nothing happened, we just randomised it again.
- : better think harder, now flame me.
-
- Of course it may have been not-random data. And of course by interpreting it
- as code You might find a 'jmp xyz' in this random data. So You have to
- translate from xyz, too...
-
- I think I'll stop this discussion now. Although it started some time before
- April 1st, I can't help feeling like an April fool...
-
- Volker
-
-