Newsgroups: comp.sys.transputer
From: andyr@wizzy.com (Andy Rabagliati)
Subject: Re: Easy way of restarting an occam program ?
Organization: W.Z.I.
Date: Mon, 25 Jul 1994 16:00:13 GMT
Message-ID: <CtI74D.JF1@wizzy.com>

In article <9879@eagle.ukc.ac.uk>, Andrew <abs@ukc.ac.uk> wrote:
>
>Hi,
>
>I need a dirty software reset mechanism as my program has too many
>states to handle the reset by individual processes :-)

The correct solution is to fix this. If this is production code, you
will have to do it some day .. but you know that.

Parallel code cannot be sloppy - it is more trouble than it is worth to
try to debug it. Your time is better spent making it Correct in the
first place.

>Is there an easy way of restarting an occam program ? Can I just 'jump'
>to some start address and have the program restart ? I suppose there
>must be some startup code that initialises workspace pointers tacked
>onto the beginning of the loaded code - is it possible to jump to this ? 


You do not say if you are booting from link or ROM.

If you booted from link, and you cannot re-load the code from link, you
may be lost. There is some initialisation code that is over-written by
data (your workspace data) after the program starts. Some investigation
of the /P option to icollect may get you further, unknown territory to me.

That aside, there are a number of possibilities here. (All the following
need the oc /w switch)

The very simple solution is the secret instruction 

  ASM
    OPR $1FF
  
That will jump to the microcode entry point of (any) transputer. However,
the hard link engines are not properly reset in this case. Use this code
to do that (plug in "bootchan" appropriately for boot-from-link) :-

[ Disclaimer - I just hand-hacked this from GUY to ASM - but it should work ]
[ Disclaimer++ fiddle a bit if you use C instead of occam ]

  --{{{  HARD chan DECLs
  CHAN OF ANY link.out.0, link.out.1, link.out.2, link.out.3 :
  PLACE link.out.0 AT 0 :
  PLACE link.out.1 AT 1 :
  PLACE link.out.2 AT 2 :
  PLACE link.out.3 AT 3 :
  [4]CHAN OF ANY link.out IS [link.out.0, link.out.1,
		              link.out.2, link.out.3] :
  CHAN OF ANY link.in.0, link.in.1, link.in.2, link.in.3 :
  PLACE link.in.0 AT 4 :
  PLACE link.in.1 AT 5 :
  PLACE link.in.2 AT 6 :
  PLACE link.in.3 AT 7 :
  [4]CHAN OF ANY link.in IS [link.in.0, link.in.1,
			     link.in.2, link.in.3] :


  CHAN OF ANY BOOTCHAN IS link.in [bootlink] :
  --}}}  
  SEQ
    --{{{  reset all channels except boot channel
    SEQ i = 1 FOR 3              -- 0 FOR 4 for boot-from-ROM
      VAL thischan IS (i+bootchan)\4 :
      CHAN OF ANY inchan  IS link.in [thischan] :
      CHAN OF ANY outchan IS link.out[thischan] :
      SEQ
	ASM
	  LDL inchan
	  RESETCH
	  LDL outchan
	  RESETCH
    --}}}

This is some code that will do boot-from-link, as a replacement for
OPR $1FF - make sure it lies at least 256 bytes above MEMSTART.

The bootstrap itself will kill other parallel processes
				(MINT; STHF; MINT; STLF)


    BYTE len :
    SEQ
      --{{{  boot
      BOOTCHAN ? len
      ASM
	MINT
	LDNLP 28        -- point to memstart, post-T414 32 bit CPU
	LDL BOOTCHAN
	LDL len
	IN
	LDL BOOTCHAN    -- boot link, needed by following bootstrap
	LDL len
	ADC 3           -- round up to word
	LDC 1
	BCNT
	NOT
	ADC 1
	AND
	LDL memstart
	ADD             -- Wptr
	LDL memstart    -- for GCALL
	REV
	GAJW
	REV             -- memstart
	GCALL
      --}}}  

This does boot-from-ROM (again, untested, sorry) :-

      ASM
	MINT
	LDNLP 28        -- point to memstart, post-T414 32 bit CPU
	GAJW
        LDC -2
        MINT
	BSUB
	GCALL


Cheers,     Andy.


--
Andy Rabagliati      andyr@wizzy.com      Consulting, Parallel Processing

