Newsgroups: comp.sys.amiga.programmer
Path: utzoo!utgpu!cunews!micor!latour!mcr
From: mcr@Sandelman.OCUnix.On.Ca (Michael Richardson)
Subject: Starting another copy of your own code (was Re: Help! (AmigaDOS CreateProc/LoadSeg)
Message-ID: <1991Mar9.170859.4810@Sandelman.OCUnix.On.Ca>
Summary: Suggest an alternative.
Organization: Sandelman Software Works, Debugging Department, Ottawa, ON
References: <63329@eerie.acsu.Buffalo.EDU> <19578@cbmvax.commodore.com> <06417.AA06417@babylon.rmt.sub.org>
Date: Sat, 9 Mar 1991 17:08:59 GMT

In article <06417.AA06417@babylon.rmt.sub.org> cbmvax.commodore.com!cbmehq!babylon!rbabel (Ralph Babel) writes:
>In article <19578@cbmvax.commodore.com>,
>ken@cbmvax.commodore.com (Ken Farinsky - CATS) writes:
>
>> LoadSeg() needs a BPTR to a seg list, which can be faked
>> like:
>>
>>         /* From Mike Sinz AmigaMail example */
>>         struct CodeHdr
>>                 {
>>                 ULONG SegSize;   /* sizeof(struct CodeHdr) */
>>                 ULONG NextSeg;   /* Must be NULL */
>>                 UWORD JumpInstr; /* set to 0x4EF9 (a jump instruction) */
>>                 APTR Function;   /* a pointer to the function */
>>                 }
>
>I'd call this self-modifying code.

  Please suggest an alternative to doing this.
  So far code like this (Hmm. I don't have a SegSize at the beginning
though) has been working on A3000s for some time now. 
  Is there now a 2.0 function for doing the same thing?

/* From Leoproc.zoo. By Leo Shwab. */
struct PhonySegList {
        BPTR    psl_NextSeg;            /*  BPTR to next element in list  */
        UWORD   psl_JMP;                /*  A 68000 JMP abs.l instruction  */
        void    (*psl_EntryPoint)();    /*  The address of the function  */
};

struct PhonySegList template = {
        NULL,                           /*  No next element.              */
        0x4EF9,                         /*  JMP abs.l                     */
        NULL                            /*  Argument for JMP instruction  */
};

...

  /*
   * Allocate a PhonySegList structure.
   */
  if((fakelist = AllocMem(sizeof(struct PhonySegList), NULL))==NULL ||
     (startup  = AllocMem(sizeof(struct SlaveStart),MEMF_PUBLIC))==NULL) {
    return(88);
  }

  /*
   * Copy the template into the allocated memory, and set the entry
   * point to the sub-process.
   */
  CopyMem(&template, fakelist, sizeof(struct PhonySegList));
  fakelist->psl_EntryPoint = SlaveStart;




-- 
   :!mcr!:            |  The postmaster never | - Pay attention only
   Michael Richardson |    resolves twice.    | to _MY_ opinions. -  
 HOME: mcr@sandelman.ocunix.on.ca +   Small Ottawa nodes contact me
 Bell: (613) 237-5629             +    about joining ocunix.on.ca!
