wenn32 wrote:so cygwin(in windows) converts from ELF to PE format correct???(so that i can run in windows)
No.
Cygwin provides two things:
- a POSIX ("Unix-ish") API, so that sources writen for Unix systems can be compiled in a Cygwin environment, too.
- a variety of tools, programs etc. for which this has already been done, making a bash ("Unix-ish") / X11 ("Unix-ish") environment available for Windows users that need one.
Cygwin does
not provide an environment in which binaries
compiled for Unix can be run.
I.e., you can take the
source code for a program originally written for Linux, BSD etc., compile that in Cygwin, and (with a little luck, some work, spit and polish) get a Windows executable.
You can
not take that same program in
binary form intended for a different system (e.g. from a Linux download mirror) and expect that binary to run on Cygwin.
suppose i have a program "X" which is a Unix-ish program(in ELF) and i can run that program in windows by using Cygwin to convert from that ELF to PE right??
Not really.
The source for e.g. "sed", compiled on Linux, results in an ELF-Linux executable.
The same source for "sed", compiled on Cygwin, results in a PE-Windows executable.
Because that is what the compiler on that system generates.
...
Make sure you understood the above before reading on.
...
The
GCC Cross-Compiler we keep talking about is the source for "gcc" (and the "binutils" package which GCC relies on), compiled on Cygwin (to give PE-Windows executables), which in turn
are configured to generate generic ELF binaries when run. I.e., the output of Cygwin's GCC toolchain runs on Windows, the output of said cross-compiler
does not run on Windows.
so i guess ELF is like standard file format which is like a portable standard on most systems right??
That, indeed, is correct. "Most systems", however, does
not include Windows.
so if i implement the same ELF in my OS then without any conversion i can run it
???
At some point in time you have to implement a "loader" component in your OS that takes executables or libraries from storage, and puts them into active memory in some appropriate way. If you decide to "go ELF", that "loader" would have to handle the ELF format.
But keep in mind that the binary format (i.e., ELF or PE) is ony one small part of the magic that is "compatibility". The other two parts would be the Application Programming Interface (API, i.e., the functions offered by your OS on the source level), and the Application Binary Interface (ABI, i.e., how an application addresses those functions on the machine level). Only if you keep all three compatible you can take a binary compiled for OS X and run it unchanged on OS Y. (The two systems would, however, be very much alike anyway. Even two different Linux distributions aren't really binary compatible that way.)
However, all you need to be able to compile the same
source code for two different operating systems is a compatibility in the API. The compiler will generate the correct binary format and address the ABI in the correct way, automatically.
----
There are two ways you could have approached at your type of question. You either:
- ...have a good understanding of operating system structures in general, and just were a bit fuzzy on the subject of binary formats. In that case, I hope I was of help, and good luck with your endeavour. Or you...
- ...lack quite crucial background knowledge on what happens "under the hood". In that case, let me flash a warning at you: Starting OS development without a good technical background will result in frustration and annoyed people, which most likely will include yourself and several forum users that feel obliged to answer questions that shouldn't be necessary. In that case, I still hope I was of help in building up your background knowledge, but I seriously suggest that you build that kind of knowledge while doing application development work. Everything you will learn there will help you in OS development, should you return - and it is a much less painful way of learning, as userspace development is much better supported by tools, books, and support websites.