ELF loading
Posted: Mon Jul 13, 2009 6:30 am
Hello osdevers!
I have recently returned to OS development after a few years of inactivity. Last time it didn't went to well, so I've started all over this time. I have used JamesM's tutorial as a base for my new operating system and modified it for my needs and style.
I'm now trying to implement user programs into my system, because I don't want my shell to be a part of the kernel itself. I have chosen ELF as the executable format for my user programs, because of its wide support and easy of use in Linux (and because the kernel is in ELF format, too). I have been looking trough the ELF specification and I've coded a parser to parse the elf header and the program and sections headers. This was actually pretty easy, but I am confused about how the prepare the file for execution. There a several things I don't fully understand.
1. When I want to compile an elf executable for my operating system will I, as far as I've figured out, need an assembly file to fetch the programs arguments from the kernel and push them as arguments for the main function, right? And this assembly file should call an exit function as well, when the main function returns? These two files should of cause be linked together.
2. I'm not sure how to link my files together (and this is partially connected with the third question). Should I specify a virtual or a physical address, or both?
3. Before I can jump to the entry address, I need to make sure the program is loaded with the correct addresses for data and so on, but is this a matter of relocation or some memory mapping?
I'm overall a little confused about all this, I have searched the forum several times without finding the answers for my questions. As you may have guessed I'm not so much into OS development yet, so I would appreciate any help, also links to some explanations on this topic
I have recently returned to OS development after a few years of inactivity. Last time it didn't went to well, so I've started all over this time. I have used JamesM's tutorial as a base for my new operating system and modified it for my needs and style.
I'm now trying to implement user programs into my system, because I don't want my shell to be a part of the kernel itself. I have chosen ELF as the executable format for my user programs, because of its wide support and easy of use in Linux (and because the kernel is in ELF format, too). I have been looking trough the ELF specification and I've coded a parser to parse the elf header and the program and sections headers. This was actually pretty easy, but I am confused about how the prepare the file for execution. There a several things I don't fully understand.
1. When I want to compile an elf executable for my operating system will I, as far as I've figured out, need an assembly file to fetch the programs arguments from the kernel and push them as arguments for the main function, right? And this assembly file should call an exit function as well, when the main function returns? These two files should of cause be linked together.
2. I'm not sure how to link my files together (and this is partially connected with the third question). Should I specify a virtual or a physical address, or both?
3. Before I can jump to the entry address, I need to make sure the program is loaded with the correct addresses for data and so on, but is this a matter of relocation or some memory mapping?
I'm overall a little confused about all this, I have searched the forum several times without finding the answers for my questions. As you may have guessed I'm not so much into OS development yet, so I would appreciate any help, also links to some explanations on this topic