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

Re: d2c on Macintosh (help!)



On Wed, Dec 22, 1999 12:08 Uhr, Rob Myers <mailto:robm@lostwax.com> wrote:
>> From: "Gabor Greif" <gabor@no.netopia.com>
>> 
>> Hi Rob,
>> 
>> I assume this is a PowerPC problem and that bootstrapping in 68k
emulation
>> is too slow to be tried (it sometimes helps to switch architectures if
>> strange things happen). Also I think you use Macsbug 6.6.
>
>I could try a 68k version. I'd rather not, though, as I've been working on
>PPC.
>Yes, I'm using Macsbug 6.6. The cursor support is nice. :-)
>
>> 1) I usually have such hard crashes if the stack expands into the heap.
You
>> can guard against this if you put some ppc watchpoints in the area
behind
>> the gd heap zone. Or you can write some patter here and check it for
>> integrity from a frequently invoked routine. If this is the cause then
>> SetApplLimit is your friend.
>
>I'm unfamiliar with watchpoints, although the MacsBug help explains these
>well enough for me to start using them. What exactly do you mean by the
area
>"behind" the gd heap zone? In the system heap or the QDGlobals area or
just
>below the end of the stack or somewhere else?

You get a THz by calling GetApplZone (Inside Mac: Memory)
This zone header contains a pointer to beyond the application heap. The
stack must not extend below this point. If you can put some watchpoints in
this area, if the stack overwites one of them, you get alerted.

>
>> 2) If you use trampolines with dynamically generated machine code
>> (shouldn't be necessary on ppc bacause of TVectors) then do not forget
to
>> correctly invalidate the instruction cache for the block(s) the
trampolines
>> will go into. Though, this does not usually corrupt the heap zone.
>
>I'm using trampolines that print out an error then die. :-) They don't
seem
>to get called, to my relief. I can flag blocks executable and flush the
>cache if needed. I'll look into TVectors, can you give me any pointers to
>documentation?

Inside Mac: PowerPC System Software. The trick is that TVectors act as jump
table entries but do not contain code. They are invoked from C by means of
ptr_glue. Look into the CodeWarrior runtime libraries for implementation
hints. The nice thing is that you can extend the TVector structure in oder
to create pretty dylan closures. IIRC r12 is set up (by ptr_glue) to point
to the TVector structure where the closed over variables can be reached.
Every regular C and C++ function pointer invocation goes over ptr_glue.

>
>> 3) From CW or Macsbug set watchpoints onto the zone header. This may
stop
>> your program just when the corruption occurs.
>
>This is what I need, as after the header gets scribbled it's a bit like
the
>opening of "Mostly Harmless" (the error handling system isn't there to
>handle the error and the system that would ask it to and do something
about
>it isn't there either....).
>
>> Hope this helps and thanks for your efforts bringing gd to the Mac!
>
>This definitely helps. Thank you!
>
>- Rob.
>
>> PS: Do you directly feed the output of gd into the CW C compiler plugin?
If
>> you plan to do so, drop me a note, I did this earlier with a toy project
>> (68k based plugin but ppc based should be similar) with nice results.
>
>This would be good, although the compiled results will need to be linked
to
>the runtime lib so I was thinking I'd need to generate a project (possibly
>in XML :-) ). Please let me know how you did this, I'd appreciate it.
>

Why don't you follow the regular CodeWarrior route by requiring the user to
put the right libraries into its project? To ease this one could make some
nice stationeries.
I fed the C plugin by loading its 68k code resource into memory and invoked
it's main entry point by passing the (augmented) CWPluginRef my plugin has
received. (On PPC you would load the C plugin's code fragment manually and
invoke main.) In that time CWPluginRef was not that opaque, so you could
fool with the function pointers directly. I guess, that a bit of reverse
engineering PluginLib4 would reveal the current structure. This means going
on thin ice, but OTOH the plugin API for compilers did not change that
much.
Why don't you use the normal CW linker for dylan output?
Sorry no way to elaborate this further, I will be accessible next two weeks
over concatenate("gabor", "68", "@", "yahoo", #('c', 'o', 'm')). Please cc
this address too.