Here are some help to port GNU Prolog.

1) I suppose you are in ROOT_DIR/src:

   . ./SETVARS        (or source CSHSETVARS if you are under csh)
   ./configure --with-c-flags=debug

--with-c-flags=debug is a "good" option to allow you to use the C
debugger, you can always use this until a final point is reached.


This allows you to execute the locally compiled version (see file DEVELOPMENT for
more info).

2) Modify the following files to create an entry M_<processor>_<os>

configure.in              (+CFLAGS and others)
EnginePl/gp_config.h.in   (M_<processor>_<os>)
EnginePl/machine.h        (+regs)
eventually look at EnginePl/arch_dep.h

3) you must be able to compile the following:

   cd EnginePl ; make engine.o engine1.o


4) Create the translation file (in the Ma2Asm/ directory). GNU Prolog compiles a
Prolog source to a low-level machine independent language called mini-assembly. You
have to write a translator for the target machine (mini-asm to assembly). You can use
an existing translation file as example and/or look at the assembly produced by
gcc. For that you can do:

   cd Ma2Asm/FromC
   make

This will create a file asm_inst.s from asm_inst.c. The study of both files can help
you to write the translater (in Ma2Asm/).

You can check your translation using the chkma program (in Ma2Asm/):

   make chkma
   ./chkma

You should obtain something like:

reg_bank=&X(0):0x8052a00   B:0x8053ac0   E:0x8054ac0  &Y(0):0x8054ab0
stack:0x8053ac0
test 1: c_code intializer...
test 1  OK
test 2: long local/global ...
test 2  OK
test 3: pl_jump/pl_ret...
test 3  OK
test 4: pl_call/pl_ret/pl_fail...
test 4  OK
test 5: prep_cp/here_cp...
test 5  OK
test 6: jump/c_ret...
test 6  OK
test 7: call_c(void)...
test 7  OK
test 8: move X(i) to Y(j)...
test 8  OK
test 9: move Y(i) to X(j)...
test 9  OK
test 10: call_c(int)...
test 10  OK
test 11: call_c(double)...
test 11  OK
test 12: call_c(string)...
test 12  OK
test 13: call_c(mem,&label,mem(...),&mem(...))...
test 13  OK
test 14: call_c(X())...
test 14  OK
test 15: call_c(Y())...
test 15  OK
test 16: call_c(FL())...
test 16  OK
test 17: call_c(FD())...
test 17  OK
test 18: call_c(lot_of_args)...
test 18  OK
test 19: call_c()+jump_ret...
test 19  OK
test 20: call_c()+fail_ret...
test 20  OK
test 21: call_c()+move_ret mem...
test 21  OK
test 22: call_c()+move_ret X()...
test 22  OK
test 23: call_c()+move_ret Y()...
test 23  OK
test 24: call_c()+move_ret FL()...
test 24  OK
test 25: call_c()+move_ret FD()...
test 25  OK
test 26: call_c()+switch_ret...
test 26  OK
MA checks suceeded

(you can use make clean-chkma to erase chkma objects/execs)

All tests must be OK else you have an error in the corresponding tested point.

At this point you should discover which part is not OK. 

5) Check that ObjChain works:

ObjChain is a way to find at run-time which Prolog modules are linked (to then
initialize them). Normally this should be OK but you can test it.

   cd EnginePl
   make test_oc
   ./test_oc

This will find 5 modules and display somthing like:

starting...
object <object #5> found  &name:0x804c200
object <object #4> found  &name:0x804c1e0
object <object #3> found  &name:0x804c1c0
object <object #2> found  &name:0x804c1a0
object <object #1> found  &name:0x804c180
finished - OK !

The important point to check is if 5 modules are found and peferably in reverse
order. If not you have to debug the file EnginePl/obj_chain.c. Since 1.3.0 we use gcc
__atribute__((constructor)).

(you can use make clean-test_oc to erase test objects/execs)


6) When this is OK (i.e. a Prolog program can be compiled and executed) you will have
to check if the stack overflow detection is ok. See file EnginePl/machine.c (function
SIGSEGV_Handler). The important point here is to obtain the address which caused the
SIGSEGV (the rest of the function detects which stack is involved from that
addresss).  look at the files EnginePl/*_SIGSEGV.C



other things to do when porting:
	ma2asm (use chkma)
	(call_c needs at least 7 args)
	test with all combinations of mapped registers

machine.c: SIGSEGV_Handler

engine1.c:
	what to do #ifndef MAP_REG_BANK

things to test:
	linedit
	floats (e.g. write(1.23),...)
	statistics
	os stuffs
	random
	ctrl/c (prg TEST_CTRLC.c)

7) Once all compile fine and pl2wam and gprolog executables are created you can check
the bootstraping by:

   cd Pl2Wam
   make check
   Bootstrap Prolog Compiler OK

the same for Built-ins;

   cd ../BipsPl
   make check
   Bootstrap Prolog Bips OK

