Page 1 of 1
Executables
Posted: Sun Dec 31, 2006 11:54 am
by Edward
I was thinking...
when I use assembly language to create a binary file I use the 'org' directive to give the initial offset of the image.
for example in a '*.com' dos executable I would use org 100h because it is loaded at (some segment):100h
in a single tasking enviroment this is fine because there is only one task at any one time.
However in a protected mode enviroment segmentation works differantly so I was wondering in pmode, how do you run for example, two instances of the same application at once, each instance must be loaded at the same offset so if you are going to create segments with base 0 and limit 4 Gi how do you run both.
I undestand that you can run two proceses at the same offsets but with differant segments by changing the base address of the segments. But I undestand OSs like Linux don't do this.
Sorry about the lack of clarity. Edward.
Posted: Sun Dec 31, 2006 12:32 pm
by Otter
OSs like Linux use paging, that means that processes have their own address space. Because of that, none of the instances of your program can see another in memory and all of them can use the same virtual base adress.
OSs without paging cannot start binary executables, because they need relocation informations.
Posted: Sun Dec 31, 2006 12:36 pm
by earlz
I'm thinking they use paging but not completely for sure...
for instance(in theory) task A is run 2 times, we'll call them process B and C, when process B's time share is gone, you do something to map addresses to another address(via paging) we then switch to C at the same address but we switched the page tables(or whatever) so that where B is loaded is actually somewhere else and such...bad explanation..
Posted: Sun Dec 31, 2006 12:42 pm
by Edward
with pageing would you create two page directories.
Then have the first two entries in those pointing to some identity mapped kernel space. but in the one for process A (assembled for offset 0xc0000000) you map say, the physical address 0x10000000 to 0xc0000000 and in the one for process B you map physical address 0x20000000 to 0xc0000000 and when you perform a task switch you change page girectories. to that both processes appear at 0xc0000000.
Is this right?
Posted: Sun Dec 31, 2006 1:42 pm
by Dex
You need to load a relocatable file format eg: PE: in the header is relocatable info, so you would use ORG 0, some address do not need fixing eg: jump 10 bytes from here, other do, so the offset is stored in the header, you jump to that offset in the program, get what at that address and add the load address (eg: you could load two of the same files one to 2MB and one to 3MB).
This is done when you load a file.
This is a simple example, read about relocatable file format for more info.
Posted: Sun Dec 31, 2006 3:00 pm
by Ready4Dis
Paging can insure all apps run from a specific location, however I recommend looking into a relocateable format as well, for example: You want a process to load a shared library at a random address, the kernel wants to load drivers into kernel space so it doesn't have to do a page table switch each time a driver function is called. There are many formats that you can use, a.out, coff,elf,pe, they all have minor differences,so find the one that fits your needs (or make your own). I am working on a custom relocation format, I have a formatter that can load either coff or a.out files and convert them (it also links them together as well). I need to make major changes though, I want to keep symbol information sometimes, which I currently don't (for things like loading a shared library!).
Posted: Sun Dec 31, 2006 4:02 pm
by Edward
Which format would You sujest. PE sounds good but does M$ have patents on it?
Posted: Sun Dec 31, 2006 6:42 pm
by earlz
no patents on PE...yet
I find it funny they call it Portable Executable format, yet nothing but windows uses it(and I think only on the PC)
Posted: Sun Dec 31, 2006 7:37 pm
by Brynet-Inc
hckr83 wrote:no patents on PE...yet
I find it funny they call it Portable Executable format, yet nothing but windows uses it(and I think only on the PC)
Indeed, But considering what they did to FAT..
It might be best to avoid Microsoft
ELF or OpenBSD's a.out is what I'd use..
PE is in itself just an extended COFF format.
Posted: Sun Dec 31, 2006 8:00 pm
by earlz
PE is in itself just an extended COFF format.
no, PE is COFF, just PE is branched out to COFF, EXE, and DLL
Posted: Mon Jan 01, 2007 7:58 am
by Edward
I'm currently using FASM. when I am creating ELF files, I decided to try ELF; everyone seems very keen on it, should I use:
'ELF' or 'ELF executable'
to produce sutible 'relocatable files'?
The former produces a file that is described by readelf as 'relocatable' and contains relocation information.
The later is used in the FASM source for linux and seems to create an executable that does not contain relocation information.
Thank you, ED
Posted: Mon Jan 01, 2007 8:36 am
by Ready4Dis
If you want relocation, use the first, if you are linking to a specific location, use the second. Executeable means that all linking information has been patched, if you are using the same address with seperate memory spaces, for example: Every application starts at 0xC0000000, so you can link it executeable at that location, and it will relocate all if it's jumps/variable access', etc to that location. If each application doesnt have a static address and you want it to be able to be loaded anywhere in memory, you must compile it non-executeable, and do the relocations when you load the program from disk using whatever address you moved it to as the base.
Posted: Mon Jan 01, 2007 8:39 am
by Candy
hckr83 wrote:PE is in itself just an extended COFF format.
no, PE is COFF, just PE is branched out to COFF, EXE, and DLL
Actually, no, PE is a further development of COFF. EXE and DLL files are specific extensions given to a particular instantiation of either PE or COFF (namely, the executable one).