This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to load and execute COFF file





From: Toralf Lund <toralf@procaptura.com>
To: Alexander Gdalevich <gdalevich@hotmail.com>
CC: crossgcc@sources.redhat.com
Subject: Re: How to load and execute COFF file
Date: Mon, 15 Sep 2003 09:15:32 +0200


You will either need to write a custom loader (this is not too difficult, COFF is a pretty simple format), or have your code move itself to the proper place in memory.


The plan is to write a loader, or rather, to modify an existing one. I'm just wondering what it needs to do, apart from obvious stuff like actually writing the data to memory.

I don't know exactly how your system works, but the loader just moves the program to the right place in memory and just jump to the entry point.

OK, I have now set up my system so that .text starts at 0x1000 (see below). It also looks like the m68k-coff linker puts the entry point ("start" symbol) at the very beginning of .text. So it's just a matter of writing the file minus headers etc. to address 0x1000, then jump there?


I somehow imagined it would be harder. Also, I still don't quit understand how I would work the magic if I were to do stuff like load several programs at once, but I don't care about that right now



You may also compile with the "-oformat binary" option to generate binary image (that will still need to be moved to the right place in memory).


Possibly a stupid question, but what would the right place in memory be?

That depends on how the memory is setup on your system. You may compile with the "-Ttext PROG_START" option to tell the compiler (or rather the linker) where to place executable. Here PROG_START would be address where you want the program placed. For instance, "-Ttext 0x00400000" would build code to run from address 0x00400000.

I have actually written a special linker script now. It will basically just define a writable memory area "ram" starting at 0x1000, which is the load address we've been using in the past, then set up sections .text, .data and .bss (in that order) with output directed to "ram". The section contents were simply copied from one of the scripts in libgloss. Hopefully, this is all I need...


- Toralf




------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]