Blame doc/README.amiga

Packit d28291
            Kjetil S. Matheussen's notes (28-11-2000)
Packit d28291
Packit d28291
Compiles under SAS/C again. Should also still compile under other
Packit d28291
Amiga compilers without big changes. I haven't checked if it still
Packit d28291
works under gcc, because I don't have gcc for Amiga. But I have
Packit d28291
updated 'Makefile', and hope it compiles fine.
Packit d28291
Packit d28291
Packit d28291
WHATS NEW:
Packit d28291
Packit d28291
1.
Packit d28291
   Made a pretty big effort in preventing GCs allocating-functions from returning
Packit d28291
   chip-mem.
Packit d28291
Packit d28291
   The lower part of the new file AmigaOS.c does this in various ways, mainly by
Packit d28291
   wrapping GC_malloc, GC_malloc_atomic, GC_malloc_uncollectable,
Packit d28291
   GC_malloc_atomic_uncollectable, GC_malloc_stubborn, GC_malloc_ignore_off_page
Packit d28291
   and GC_malloc_atomic_ignore_off_page. GC_realloc is also wrapped, but
Packit d28291
   doesn't do the same effort in preventing to return chip-mem.
Packit d28291
   Other allocating-functions (f.ex. GC_*_typed_) can probably be
Packit d28291
   used without any problems, but beware that the warn hook will not be called.
Packit d28291
   In case of problems, don't define GC_AMIGA_FASTALLOC.
Packit d28291
Packit d28291
   Programs using more time actually using the memory allocated
Packit d28291
   (instead of just allocate and free rapidly) have
Packit d28291
   the most to earn on this, but even gctest now normally runs twice
Packit d28291
   as fast and uses less memory, on my poor 8MB machine.
Packit d28291
Packit d28291
   The changes have only effect when there is no more
Packit d28291
   fast-mem left. But with the way GC works, it
Packit d28291
   could happen quite often. Beware that an atexit handler had to be added,
Packit d28291
   so using the abort() function will make a big memory-loss.
Packit d28291
   If you absolutely must call abort() instead of exit(), try calling
Packit d28291
   the GC_amiga_free_all_mem function before abort().
Packit d28291
Packit d28291
   New Amiga-specific compilation flags:
Packit d28291
Packit d28291
   GC_AMIGA_FASTALLOC - By NOT defining this option, GC will work like before,
Packit d28291
                        it will not try to force fast-mem out of the OS, and
Packit d28291
                        it will use normal calloc for allocation, and the rest
Packit d28291
                        of the following flags will have no effect.
Packit d28291
Packit d28291
   GC_AMIGA_ONLYFAST - Makes GC never to return chip-mem. GC_AMIGA_RETRY have
Packit d28291
                       no effect if this flag is set.
Packit d28291
Packit d28291
   GC_AMIGA_GC - If gc returns NULL, do a GC_gcollect, and try again. This
Packit d28291
                 usually is a success with the standard GC configuration.
Packit d28291
                 It is also the most important flag to set to prevent
Packit d28291
                 GC from returning chip-mem. Beware that it slows down a lot
Packit d28291
                 when a program is rapidly allocating/deallocating when
Packit d28291
                 there's either very little fast-memory left or very little
Packit d28291
                 chip-memory left. Its not a very common situation, but gctest
Packit d28291
                 sometimes (very rare) use many minutes because of this.
Packit d28291
Packit d28291
   GC_AMIGA_RETRY - If gc succeed allocating memory, but it is chip-mem,
Packit d28291
                    try again and see if it is fast-mem. Most of the time,
Packit d28291
                    it will actually return fast-mem for the second try.
Packit d28291
                    I have set max number of retries to 9 or size/5000. You
Packit d28291
                    can change this if you like. (see GC_amiga_rec_alloc())
Packit d28291
Packit d28291
   GC_AMIGA_PRINTSTATS - Gather some statistics during the execution of a
Packit d28291
                         program, and prints out the info when the atexit-handler
Packit d28291
                         is called.
Packit d28291
Packit d28291
   My recommendation is to set all this flags, except GC_AMIGA_PRINTSTATS and
Packit d28291
   GC_AMIGA_ONLYFAST.
Packit d28291
Packit d28291
   If your program demands high response-time, you should
Packit d28291
   not define GC_AMIGA_GC, and possible also define GC_AMIGA_ONLYFAST.
Packit d28291
   GC_AMIGA_RETRY does not seem to slow down much.
Packit d28291
Packit d28291
   Also, when compiling up programs, and GC_AMIGA_FASTALLOC was not defined when
Packit d28291
   compiling gc, you can define GC_AMIGA_MAKINGLIB to avoid having these allocation-
Packit d28291
   functions wrapped. (see gc.h)
Packit d28291
Packit d28291
   Note that GC_realloc must not be called before any of
Packit d28291
   the other above mentioned allocating-functions have been called. (shouldn't be
Packit d28291
   any programs doing so either, I hope).
Packit d28291
Packit d28291
   Another note. The allocation-function is wrapped when defining
Packit d28291
   GC_AMIGA_FASTALLOC by letting the function go thru the new
Packit d28291
   GC_amiga_allocwrapper_do function-pointer (see gc.h). Means that
Packit d28291
   sending function-pointers, such as GC_malloc, GC_malloc_atomic, etc.,
Packit d28291
   for later to be called like f.ex this, (*GC_malloc_function_pointer)(size),
Packit d28291
   will not wrap the function. This is normally not a big problem, unless
Packit d28291
   all allocation function is called like this, which will cause the
Packit d28291
   atexit un-allocating function never to be called. Then you either
Packit d28291
   have to manually add the atexit handler, or call the allocation-
Packit d28291
   functions function-pointer functions like this;
Packit d28291
   (*GC_amiga_allocwrapper_do)(size,GC_malloc_function_pointer).
Packit d28291
   There are probably better ways this problem could be handled, unfortunately,
Packit d28291
   I didn't find any without rewriting or replacing a lot of the GC-code, which
Packit d28291
   I really didn't want to. (Making new GC_malloc_* functions, and just
Packit d28291
   define f.ex GC_malloc as GC_amiga_malloc should work too).
Packit d28291
Packit d28291
Packit d28291
   New Amiga-specific function:
Packit d28291
Packit d28291
     void GC_amiga_set_toany(void (*func)(void));
Packit d28291
Packit d28291
   'func' is a function that will be called right before gc has to change
Packit d28291
   allocation-method from MEMF_FAST to MEMF_ANY. Ie. when it is likely
Packit d28291
   it will return chip-mem.
Packit d28291
Packit d28291
Packit d28291
2. A few small compiler-specific additions to make it compile with SAS/C again.
Packit d28291
Packit d28291
3. Updated and rewritten the smakefile, so that it works again and that
Packit d28291
   the "unnecessary" 'SCOPTIONS' files could be removed. Also included
Packit d28291
   the cord-smakefile stuff in the main smakefile, so that the cord smakefile
Packit d28291
   could be removed too. By writing smake -f Smakefile.smk, both gc.lib and
Packit d28291
   cord.lib will be made.
Packit d28291
Packit d28291
Packit d28291
Packit d28291
STILL MISSING:
Packit d28291
Packit d28291
Programs can not be started from workbench, at least not for SAS/C. (Martin
Packit d28291
Tauchmanns note about that it now works with workbench is definitely wrong
Packit d28291
when concerning SAS/C).  An iconx-script solves this problem.
Packit d28291
Packit d28291
Packit d28291
BEWARE!
Packit d28291
Packit d28291
-To run gctest, set the stack to around 200000 bytes first.
Packit d28291
-SAS/C-specific: cord will crash if you compile gc.lib with
Packit d28291
 either parm=reg or parm=both. (missing legal prototypes for
Packit d28291
 function-pointers someplace is the reason I guess.).
Packit d28291
Packit d28291
Packit d28291
tested with software: Radium, http://www.stud.ifi.uio.no/~ksvalast/radium/
Packit d28291
tested with hardware: MC68060
Packit d28291
Packit d28291
Packit d28291
                           Martin Tauchmann's notes             (1-Apr-99)
Packit d28291
Packit d28291
Works now, also with the GNU-C compiler V2.7.2.1. <ftp://ftp.unina.it/pub/amiga/geekgadgets/amiga/m68k/snapshots/971125/amiga-bin/>
Packit d28291
Modify the `Makefile`
Packit d28291
CC=cc $(ABI_FLAG)
Packit d28291
to
Packit d28291
CC=gcc $(ABI_FLAG)
Packit d28291
Packit d28291
TECHNICAL NOTES
Packit d28291
Packit d28291
- `GC_get_stack_base()`, `GC_register_data_segments()` works now with every
Packit d28291
   C compiler; also Workbench.
Packit d28291
Packit d28291
- Removed AMIGA_SKIP_SEG, but the Code-Segment must not be scanned by GC.
Packit d28291
Packit d28291
Packit d28291
PROBLEMS
Packit d28291
- When the Linker, does`t merge all Code-Segments to an single one. LD of GCC
Packit d28291
  do it always.
Packit d28291
Packit d28291
- With ixemul.library V47.3, when an GC program launched from another program
Packit d28291
  (example: `Make` or `if_mach M68K AMIGA gctest`), `GC_register_data_segments()`
Packit d28291
  found the Segment-List of the caller program.
Packit d28291
  Can be fixed, if the run-time initialization code (for C programs, usually *crt0*)
Packit d28291
  support `__data` and `__bss`.
Packit d28291
Packit d28291
- PowerPC Amiga currently not supported.
Packit d28291
Packit d28291
- Dynamic libraries (dyn_load.c) not supported.
Packit d28291
Packit d28291
Packit d28291
TESTED WITH SOFTWARE
Packit d28291
Packit d28291
`Optimized Oberon 2 C` (oo2c) <http://cognac.informatik.uni-kl.de/download/index.html>
Packit d28291
Packit d28291
Packit d28291
TESTED WITH HARDWARE
Packit d28291
Packit d28291
MC68030
Packit d28291
Packit d28291
Packit d28291
                           Michel Schinz's notes
Packit d28291
Packit d28291
WHO DID WHAT
Packit d28291
Packit d28291
The original Amiga port was made by Jesper Peterson. I (Michel Schinz)
Packit d28291
modified it slightly to reflect the changes made in the new official
Packit d28291
distributions, and to take advantage of the new SAS/C 6.x features. I also
Packit d28291
created a makefile to compile the "cord" package (see the cord
Packit d28291
subdirectory).
Packit d28291
Packit d28291
TECHNICAL NOTES
Packit d28291
Packit d28291
In addition to Jesper's notes, I have the following to say:
Packit d28291
Packit d28291
- Starting with version 4.3, gctest checks to see if the code segment is
Packit d28291
  added to the root set or not, and complains if it is. Previous versions
Packit d28291
  of this Amiga port added the code segment to the root set, so I tried to
Packit d28291
  fix that. The only problem is that, as far as I know, it is impossible to
Packit d28291
  know which segments are code segments and which are data segments (there
Packit d28291
  are indeed solutions to this problem, like scanning the program on disk
Packit d28291
  or patch the LoadSeg functions, but they are rather complicated). The
Packit d28291
  solution I have chosen (see os_dep.c) is to test whether the program
Packit d28291
  counter is in the segment we are about to add to the root set, and if it
Packit d28291
  is, to skip the segment. The problems are that this solution is rather
Packit d28291
  awkward and that it works only for one code segment. This means that if
Packit d28291
  your program has more than one code segment, all of them but one will be
Packit d28291
  added to the root set. This isn't a big problem in fact, since the
Packit d28291
  collector will continue to work correctly, but it may be slower.
Packit d28291
Packit d28291
  Anyway, the code which decides whether to skip a segment or not can be
Packit d28291
  removed simply by not defining AMIGA_SKIP_SEG. But notice that if you do
Packit d28291
  so, gctest will complain (it will say that "GC_is_visible produced wrong
Packit d28291
  failure indication"). However, it may be useful if you happen to have
Packit d28291
  pointers stored in a code segment (you really shouldn't).
Packit d28291
Packit d28291
  If anyone has a good solution to the problem of finding, when a program
Packit d28291
  is loaded in memory, whether a segment is a code or a data segment,
Packit d28291
  please let me know.
Packit d28291
Packit d28291
Packit d28291
                          Jesper Peterson's notes
Packit d28291
Packit d28291
ADDITIONAL NOTES FOR AMIGA PORT
Packit d28291
Packit d28291
These notes assume some familiarity with Amiga internals.
Packit d28291
Packit d28291
WHY I PORTED TO THE AMIGA
Packit d28291
Packit d28291
The sole reason why I made this port was as a first step in getting
Packit d28291
the Sather(*) language on the Amiga. A port of this language will
Packit d28291
be done as soon as the Sather 1.0 sources are made available to me.
Packit d28291
Given this motivation, the garbage collection (GC) port is rather
Packit d28291
minimal.
Packit d28291
Packit d28291
(*) For information on Sather read the comp.lang.sather newsgroup.
Packit d28291
Packit d28291
LIMITATIONS
Packit d28291
Packit d28291
This port assumes that the startup code linked with target programs
Packit d28291
is that supplied with SAS/C versions 6.0 or later. This allows
Packit d28291
assumptions to be made about where to find the stack base pointer
Packit d28291
and data segments when programs are run from WorkBench, as opposed
Packit d28291
to running from the CLI. The compiler dependent code is all in the
Packit d28291
GC_get_stack_base() and GC_register_data_segments() functions, but
Packit d28291
may spread as I add Amiga specific features.
Packit d28291
Packit d28291
Given that SAS/C was assumed, the port is set up to be built with
Packit d28291
"smake" using the "SMakefile". Compiler options in "SCoptions" can
Packit d28291
be set with "scopts" program. Both "smake" and "scopts" are part of
Packit d28291
the SAS/C commercial development system.
Packit d28291
Packit d28291
In keeping with the porting philosophy outlined above, this port
Packit d28291
will not behave well with Amiga specific code. Especially not inter-
Packit d28291
process comms via messages, and setting up public structures like
Packit d28291
Intuition objects or anything else in the system lists. For the
Packit d28291
time being the use of this library is limited to single threaded
Packit d28291
ANSI/POSIX  compliant or near-compliant code. (ie. Stick to stdio
Packit d28291
for now). Given this limitation there is currently no mechanism for
Packit d28291
allocating "CHIP" or "PUBLIC" memory under the garbage collector.
Packit d28291
I'll add this after giving it considerable thought. The major
Packit d28291
problem is the entire physical address space may have to me scanned,
Packit d28291
since there is no telling who we may have passed memory to.
Packit d28291
Packit d28291
If you allocate your own stack in client code, you will have to
Packit d28291
assign the pointer plus stack size to GC_stackbottom.
Packit d28291
Packit d28291
The initial stack size of the target program can be compiled in by
Packit d28291
setting the __stack symbol (see SAS documentation). It can be over-
Packit d28291
ridden from the CLI by running the AmigaDOS "stack" program, or from
Packit d28291
the WorkBench by setting the stack size in the tool types window.
Packit d28291
Packit d28291
SAS/C COMPILER OPTIONS (SCoptions)
Packit d28291
Packit d28291
You may wish to check the "CPU" code option is appropriate for your
Packit d28291
intended target system.
Packit d28291
Packit d28291
Under no circumstances set the "StackExtend" code option in either
Packit d28291
compiling the library or *ANY* client code.
Packit d28291
Packit d28291
All benign compiler warnings have been suppressed. These mainly
Packit d28291
involve lack of prototypes in the code, and dead assignments
Packit d28291
detected by the optimizer.
Packit d28291
Packit d28291
THE GOOD NEWS
Packit d28291
Packit d28291
The library as it stands is compatible with the GigaMem commercial
Packit d28291
virtual memory software, and probably similar PD software.
Packit d28291
Packit d28291
The performance of "gctest" on an Amiga 2630 (68030 @ 25Mhz)
Packit d28291
compares favorably with an HP9000 with similar architecture (a 325
Packit d28291
with a 68030 I think).
Packit d28291
Packit d28291
-----------------------------------------------------------------------