Page 1 of 1
Accessing functions in plain binary files
Posted: Thu May 22, 2003 12:25 pm
by Kensho
Hi there,
Well, I've just started designing my OS, and while thinking about the modularity issue, I've came across a question, about something I never needed before, and can't quite sure find how to handle it.
Ok, I've decided that modules should have no format, or be, plain binary; and what can be found in modules, are simply classes with virtual functions, which I may or may not call Interface. Now, what I don't know, is how to find out the address of the classes, and the functions to call... It may be easier, if instead of classes I have only C-type functions, but still, I don't quite know how this works.
Can anyone help me out with this issue?
Thanks in advance, and good programming.
Re:Accessing functions in plain binary files
Posted: Thu May 22, 2003 2:16 pm
by df
no.
you need a file format or it wont work.
you need to record offsets, relocations, names etc.
pe, elf, coff, etc.
unless you write your own simplified version.
Re:Accessing functions in plain binary files
Posted: Fri May 23, 2003 1:19 am
by Pype.Clicker
very simplified format :
[ interface identifier ] [ amount of methods ] [ methods pointer in an array, relative to the module start]
[plain code]
However, there are other problems that just "locating the functions" in case of a dynamically loaded component:
- the component doesn't know in advance where it will be loaded, thus needing for things like relocations (patching addresses at load-time) or position-independent code (which also needs special structures to work like global offset tables, etc. , iirc)
- the component must be able to call other components, thus being able to link to the existent system.
A way you could have plain binary file would be to start at offset 0 with module initialisation routine and that initializor would perform any required patch (provided that you pass it a structure describing how to make elementary operations like finding a component, linking to it, offering its own component to the system, etc.)
I've tried this earlier and named it "S-DLODS", but i quickly found that having to write a complex INIT() function for every module was quite a nuisance (because it's much bug-prone) and inefficient (because you actually duplicate the loader code in every module).
Re:Accessing functions in plain binary files
Posted: Fri May 23, 2003 6:36 am
by Kensho
Hmm ok, I understand; Several file formats have came into my mind as I thought about this, but there were one thing that made me think about it... I don't know if any of you has looked into V2 OS, but they use straight binary files for the modules... that made me wonder a bit about it, but after taking a better look, seems they adopted a model similar to you "S-DLODS". Anyway, thanks for the help, I now understand, and will continue on with the OS design.
Greetings to all.
Re:Accessing functions in plain binary files
Posted: Tue Jun 03, 2003 1:20 pm
by slacker
then why does windows use drivers that are already compiled like floppy.sys? how are functions called in the driver?
Re:Accessing functions in plain binary files
Posted: Wed Jun 04, 2003 1:20 am
by Pype.Clicker
maybe i just need to refresh my knowledge, but afaik, .SYS and .VXD files are just modified .EXE/.DLL that hold additionnal information for the drivers manager.
Note that it's not a problem for your modules/drivers to be compiled provided that the compiler left enough informations about how to link things together at load-time (i.e. relocation lists, symbol tables, dependencies, etc.)
The problem here was to access stuff in a plain binary file, i.e. just 1s and 0s of code or static data without any assumption on how they are structured etc. (or maybe very limited and static assumptions like "the first byte of the file is the entry point for the module")