Port-next68k archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Nested functions on next68k



So I started to work on putting all my various tools on next68k...and
started getting mysterious coredumps which went away when I started
single-stepping with gdb.  It appears nested functions simply do not
work on 68040s with the versions of gcc in 1.4T and 4.0.1: the
trampoline is built on the stack but the data cache is not pushed, nor
is the instruction cache invalidated, for the affected addresses.

I looked up the cache control instructions, only to find they're
supervisor-mode-only.  But I found that move16 is documented as doing
d$ pushes-and-invalidates; I tried updating gcc's config to insert
move16 instructions to move the trampoline onto itself.  This didn't
help; I don't know whether it's because the documentation is wrong or
because the i$ isn't getting invalidated or what.

I then started looking at supporting nested functions using an
alternative method.  Specifically, instead of stack trampolines, I was
looking at having function pointers point to an 8-byte block which
includes a static chain pointer and a pointer to the machine code; for
non-nested functions, the pointer is ignored.  This means the calling
sequence becomes more complex at the machine-code level.  While I was
poking around looking for assembly files containing calls to C code, I
was reading the run-time linker, and found it has code to do exactly
what I care about here: arrange that instructions, written as data, are
suitable to be executed as instructions.  (This is done with a
fast-path syscall "trap #12".)

So I changed gcc to use that instead, rebuilt one of my tools with the
resulting cc1, and it no logner crashes.  I'm now doing a rebuild of
the whole system with this change and will then rebuild the affected
tools with that; if they then work as well as I expect, I'll post the
patch here - it's small.  (Not that I expect many people are using
nested functions on next68k, especially in view of how long this
remained unfixed, but all it takes is one person helped for me to
consider it worth having been done.)

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index