Cant wrap my head around executables.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Yuruusan

Cant wrap my head around executables.

Post by Yuruusan »

This might be a dumb question, but I cant seem to grasp the principle on how to make my asm loader load up a play C binary file. Have not found anny in-depth enough documents on it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Cant wrap my head around executables.

Post by Solar »

Well, first you need access to the hard drive, i.e. driver and file system. (Or, you need the binary in a fixed, known location instead of "knowing" the file system. You still need the driver though.)

Then you have to copy the executable into physical memory, and jmp to the entry point of the executable. Beware that the executable must either be loaded to the address it was compiled for, or you have to do relocation (which you probably don't want to do).

Or you could use GRUB to load and start your ELF binary... ;-) (I know, shameless plug... ;-) )
Every good solution is obvious once you've found it.
Yuruusan

Re:Cant wrap my head around executables.

Post by Yuruusan »

Ok, that actualy cleared things up a bit :) Re there anny file system tutorials around. Im actualy interested in creating my own file system anny good docs on that?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Cant wrap my head around executables.

Post by Pype.Clicker »

hmm, before you design your own filesystem, i suggest you do the following:
  • make sure you fully understand FAT filesystems, for it has virtually all the flaws you could want to avoid. Information about FAT filesystems are available on Operating System Resource Center (see .:QuickLinkz:.)
  • get a look at how Unix file systems are organized, especially make sure you fully understand the concepts of inode, indirect block index, double indirect, etc.
  • Check Andrew Tannenbaum's paper on NTFS. "Knowing yourself without knowing your enemy only gives you half a chance to win". Imho, NTFS is very interresting because it uses files even to implement files. This means it's very straightforward to read an NTFS partition and that the same FS organization can be kept while the algorithms that perform allocation, fragmentation reduction, data locality etc. can be upgraded transparently from one release to another... However, as these algorithms are usually not divulged to the unauthorized ones (us), it's hard to write a good read/write NTFS driver if you're not at MS research center :(
  • Get a look at journalized file systems. Make sure you get the principle. I also suggest you get a look at Reiser's internal structure, which uses B+Tree for storing files in a very smart way ...
When this will be done, i suggest you address the File System in a layered approach: First there is blocks allocation, on top of which you create 'sequence of blocks' for different purposes, and one of those purpose is to create files. Then, when you'll be able to read and write at some specific position in a 'sequence of block', you can start deciding how you'll deal with metadatas like file name, access right, timestamps, etc.

some resource:
http://search.barnesandnoble.com/bookse ... 1558604979

some related threads:
FileSystems
'How do i create a filesystem'
Filesystem Loading/read in
FileSystem Design
Brainstorming: "What would you put in a FileSystem?"
Schol-R-LEA

Re:Cant wrap my head around executables.

Post by Schol-R-LEA »

Once you do get to point of needing a loader (after you've implemented your file system), try looking into the book Linkers and Loaders by John Levine. It gives a detailed explanation of the loading process, including issues of relocation, Position Independent Code, etc.
Post Reply