Just how position independent is PIC ?
Posted: Tue Aug 03, 2004 11:00 pm
I was planning to do my kernel as a pure binary - no ELF, PE, COFF stuff.
The only problem is, I have to be able to load modules (for floppy, IDE, SCSI, etc) as apropriate (why waste 3 kB on an FDC driver if the machine ain't got one?). So I figured, just allocate some memory, load some pure binary module into it, let that module start with code that uses my system call interrupt to register it's function calls (just simple pointers). But that leaves me with 2 problems:
- All the module's code must contain *only* relative jumps and relative function calls or things will go horribly wrong. If I tell the compiler to generate position independant code, will it do exactly what I want. My compiler is MinGW32 (yes, I'm using Windows as a development platform for now). I'm using NASM to make small assembly functions - MinGW32's inline assembly syntax sucks. (good old TurboPascal's syntax for inline ASM was *way* better).
- The module's initialisation code must somehow discover what the addresses of it's functions are. I was thinking - do a short jump to push EIP, read that, make a pointer to a function, add the two together - presto! But I'm not entirely sure this will work.
BTW, the main motivation for this setup is that writing a linker/relocater will probably take up to much of my time, plus, the documentation for the ELF format is quite fuzzy on how to actually relocate and ELF file.
Any hints/tips/comments/etc. are appreciated.
TIA, Rogier "Dino" de Groot
The only problem is, I have to be able to load modules (for floppy, IDE, SCSI, etc) as apropriate (why waste 3 kB on an FDC driver if the machine ain't got one?). So I figured, just allocate some memory, load some pure binary module into it, let that module start with code that uses my system call interrupt to register it's function calls (just simple pointers). But that leaves me with 2 problems:
- All the module's code must contain *only* relative jumps and relative function calls or things will go horribly wrong. If I tell the compiler to generate position independant code, will it do exactly what I want. My compiler is MinGW32 (yes, I'm using Windows as a development platform for now). I'm using NASM to make small assembly functions - MinGW32's inline assembly syntax sucks. (good old TurboPascal's syntax for inline ASM was *way* better).
- The module's initialisation code must somehow discover what the addresses of it's functions are. I was thinking - do a short jump to push EIP, read that, make a pointer to a function, add the two together - presto! But I'm not entirely sure this will work.
BTW, the main motivation for this setup is that writing a linker/relocater will probably take up to much of my time, plus, the documentation for the ELF format is quite fuzzy on how to actually relocate and ELF file.
Any hints/tips/comments/etc. are appreciated.
TIA, Rogier "Dino" de Groot