Relocatable code.

GFA, ASM, STOS, ...

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
SoLo2
Captain Atari
Captain Atari
Posts: 207
Joined: Wed Feb 04, 2004 4:09 am
Location: Spain
Contact:

Relocatable code.

Postby SoLo2 » Sun Mar 28, 2004 11:38 pm

Hello!

I was packin with IcePacker v2.4
and it asked me if I wanted my
intro code to be relocatable after
depacking. Hmmm, how???

I suppose I haven't understand
relocation in the Atari ST yet.

I knew of relocatable code, e.g.
a program that is PC relative.

Now, when a program is loaded,
and it may be loaded anywhere
in the ST's memory, must it be
always relocated?

Is this a job for TOS or any other
operating system?

Goes the icepacker changing
some opcodes (absolute jmps
or such), so that the code stays
relocatable. I think this is a big
effort for a depacker.

Has anybody some knowledge
about relocatable code?


Thanks,
SoLo2
~~~~~~~~~~~~~~~~~~~~~~~~~~*~~~
The BITS Club http://bits.atari.org

User avatar
rb
Netatari Developer
Netatari Developer
Posts: 397
Joined: Tue Apr 15, 2003 1:06 pm
Location: London UK

Postby rb » Mon Mar 29, 2004 6:33 am

hi

every st program has a relocation table right after the data section. this can be empty though. at the beginning of each program is a header which has a pointer to this table.

the first entry is either 0 or the first relocatable address relative to the prog start followed by bytes which will be added to the last relocatible address. (see atari compendium for details)

so when icepacker packs a program it has already the relocation table there.. it just packs it too, and uses these table itself while unpacking. if the whole code is pc relative or the prog is always loaded at the same address and compiled for this scenario then the packer has no need for including relocation code.

cheers
rb

User avatar
Grazey / PHF
Captain Atari
Captain Atari
Posts: 487
Joined: Fri Jun 21, 2002 12:50 pm
Location: Montreal, Quebec
Contact:

Postby Grazey / PHF » Mon Mar 29, 2004 9:25 am

Spot on rb,

Yeah if you make all your code PC-Relative e.g.

lea table(pc),a0 etc

then tell Ice 2.4 not to relocate the code. This will reduce the PRG size by a few bytes.

Grz
http://phf.atari.org - demo coders since 1983
http://sndh.atari.org - Maintainer of the Atari ST chip music archive
http://www.scenemusic.net - Nectarine Administrator

User avatar
Orion_
Captain Atari
Captain Atari
Posts: 337
Joined: Sat Jan 10, 2004 12:20 pm
Location: France
Contact:

Postby Orion_ » Mon Mar 29, 2004 3:18 pm

I've a lot of problem with relocation.
when I try to start a program from my bootstrap I've to load it at a defined memory location (I use ORG) and I must not use any absolute instruction :( that's hard, I've a lot of error because of that.
can I use the relocation code of IcePack ?
e.g: loading the .prg in memory skipping the PRG header and jump to the relocation routine entry ?

User avatar
Grazey / PHF
Captain Atari
Captain Atari
Posts: 487
Joined: Fri Jun 21, 2002 12:50 pm
Location: Montreal, Quebec
Contact:

Postby Grazey / PHF » Mon Mar 29, 2004 4:45 pm

Orion
No the best thing to do is assemble your program as a PRG (this includes the relocation table)

From your boot sector load it in at ADDRESS - $1c

($1c is the length of a program header).

Then use some code which relocates the data to where ever you want.

so you'd have something like .........

lea filename,a0
lea loadaddress-$1c,a1
bsr loadit

lea loadaddress-$1c,a0
bsr relocate
jmp $1c(a0)

if you need the relocation code just ask.

Grazey
http://phf.atari.org - demo coders since 1983

http://sndh.atari.org - Maintainer of the Atari ST chip music archive

http://www.scenemusic.net - Nectarine Administrator

User avatar
Orion_
Captain Atari
Captain Atari
Posts: 337
Joined: Sat Jan 10, 2004 12:20 pm
Location: France
Contact:

Postby Orion_ » Mon Mar 29, 2004 5:12 pm

If you can send me the relocation code it would help me a lot, thanks :)
or at least, explain me how work exactly the relocation table.
because actually this is a real nightmare to run code after my boot strap :cry:

User avatar
Grazey / PHF
Captain Atari
Captain Atari
Posts: 487
Joined: Fri Jun 21, 2002 12:50 pm
Location: Montreal, Quebec
Contact:

Postby Grazey / PHF » Mon Mar 29, 2004 5:34 pm

Can you send me your email address to

grazey@atari.org

Grz
http://phf.atari.org - demo coders since 1983

http://sndh.atari.org - Maintainer of the Atari ST chip music archive

http://www.scenemusic.net - Nectarine Administrator

Pink/RG
Moderator
Moderator
Posts: 32
Joined: Tue Dec 17, 2002 5:54 pm
Location: Guildford, UK
Contact:

Postby Pink/RG » Tue Mar 30, 2004 12:45 pm

here's a bit of code from GodLib that relocates program files, may help you to understand things:

Code: Select all


typedef unsigned char U8;
typedef signed char   S8;
typedef unsigned int  U16;
typedef signed int    S16;
typedef unsigned long U32;
typedef signed long   S32;

typedef   struct
{
   U16   Magic;
   U32   TextSize;
   U32   DataSize;
   U32   BSSSize;
   U32   SymbolTableSize;
   U16   Reserved[ 5 ];
} sProgramHeader;

void Program_Relocate(   const sProgramHeader * apHeader )
{
   U8 *   lpText;
   U8 *   lpRelocTable;
   U8      lFix;
   U32      lOffset;
   U32      lMax;

   if( !apHeader )
   {
      return;
   }

   lpText  = (U8*)apHeader;
   lpText += sizeof( sProgramHeader );

   lpRelocTable  = lpText;
   lpRelocTable += apHeader->TextSize;
   lpRelocTable += apHeader->DataSize;
   lpRelocTable += apHeader->SymbolTableSize;

   lOffset = *(U32*)lpRelocTable;
   lpRelocTable += 4;
   lpText       += lOffset;

   lMax = apHeader->TextSize + apHeader->DataSize;

   if( lOffset )
   {
      *(U32*)&lpText[ lOffset ] += (U32)lpText;
      while( *lpRelocTable )
      {
         lFix = *lpRelocTable++;
         if( 1 == lFix )
         {
            lOffset += 254;
         }
         else
         {
            lOffset += lFix;
            if( lOffset < lMax )
            {
               *(U32*)&lpText[ lOffset ] += (U32)lpText;
            }
         }
      }
   }
}


User avatar
Grazey / PHF
Captain Atari
Captain Atari
Posts: 487
Joined: Fri Jun 21, 2002 12:50 pm
Location: Montreal, Quebec
Contact:

Postby Grazey / PHF » Tue Mar 30, 2004 12:52 pm

Arrgh "C" ?!!!!?!

isn't this the 'coding' forum ? not the 'programming' forum! :wink:

Grazey ducks

Artillery ahoy!
http://phf.atari.org - demo coders since 1983

http://sndh.atari.org - Maintainer of the Atari ST chip music archive

http://www.scenemusic.net - Nectarine Administrator

User avatar
tobe
Atari God
Atari God
Posts: 1459
Joined: Sat Jan 24, 2004 10:06 am
Location: Lyon, France
Contact:

Postby tobe » Tue Mar 30, 2004 2:23 pm

C is a very good coding langage !

Pink, please, could you tell me what compiler you use ?
I tried Pure C but it use a very old syntax i can't stand !

Edit: I remember there was a asm rout in an old french STMag, but i can't remember wich, maybe someone can find it ?
Last edited by tobe on Tue Mar 30, 2004 2:25 pm, edited 1 time in total.
step 1: introduce bug, step 2: fix bug, step 3: goto step 1.

User avatar
Orion_
Captain Atari
Captain Atari
Posts: 337
Joined: Sat Jan 10, 2004 12:20 pm
Location: France
Contact:

Postby Orion_ » Tue Mar 30, 2004 2:24 pm

thanks Grazey :)
that work very well :wink:

raaaahhhhh no more tweaking .... :P

User avatar
Orion_
Captain Atari
Captain Atari
Posts: 337
Joined: Sat Jan 10, 2004 12:20 pm
Location: France
Contact:

Postby Orion_ » Tue Mar 30, 2004 2:26 pm

tobe wrote:C is a very good coding langage !

yes, but not on an atari at only 8MHz trying to do realtime effect ;)

User avatar
tobe
Atari God
Atari God
Posts: 1459
Joined: Sat Jan 24, 2004 10:06 am
Location: Lyon, France
Contact:

Postby tobe » Tue Mar 30, 2004 2:29 pm

Really, i use to code realtime effects with GFA, i ithink C works better :lol: !
step 1: introduce bug, step 2: fix bug, step 3: goto step 1.

User avatar
rb
Netatari Developer
Netatari Developer
Posts: 397
Joined: Tue Apr 15, 2003 1:06 pm
Location: London UK

Postby rb » Tue Mar 30, 2004 2:31 pm

hi

this has nothing to do with C at all but rather with the quality of compilation :)

C has always been considered as some kind of extended assembler.

apart from that if coders don't know their assembler language inside out they can produce inefficient code just the same

cheers
rb

Pink/RG
Moderator
Moderator
Posts: 32
Joined: Tue Dec 17, 2002 5:54 pm
Location: Guildford, UK
Contact:

Postby Pink/RG » Tue Mar 30, 2004 2:31 pm

grz: you cheeky monkey ;)

tobe: i use purec too.

User avatar
tobe
Atari God
Atari God
Posts: 1459
Joined: Sat Jan 24, 2004 10:06 am
Location: Lyon, France
Contact:

Postby tobe » Tue Mar 30, 2004 2:41 pm

thanks Pink, so pure C can understand new syntax with forward decls !?
I will try it again this evening !
step 1: introduce bug, step 2: fix bug, step 3: goto step 1.

User avatar
ggn
Atari God
Atari God
Posts: 1137
Joined: Sat Dec 28, 2002 4:49 pm

Postby ggn » Mon Apr 05, 2004 10:07 am

Pink,

Don't post this stuff here, it's toxic :)
On another note: it's been a while since we last communicated. I just hope they'll stick me in front of a PC in the Navy, so we can finish you-know-what :)

/George
is 73 Falcon patched atari games enough ? ^^


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 1 guest