Problem with drivers

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
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Problem with drivers

Post by Karlosoft »

Hi!, I'm developing the support of dynamic drivers to my os. The problem is that I have to provide a way to calculate again all the addresses adding the base location of the driver to the address itself. How to do it? I thought to link the compiled sources with a porting of ld, using a script generated every time from the manager of drivers. What libraries are required?
Selenic
Member
Member
Posts: 123
Joined: Sat Jan 23, 2010 2:56 pm

Re: Problem with drivers

Post by Selenic »

Look up the specification for your object file format - it should tell you how to do relocations (the ELF article's "Relocation" section gives you an overview of the process you need for any format). All you need is a small extension to the loader you're going to write/have anyway. That and LD's -q option, which makes it emit relocations in the executable (would -r work too? Either way, I believe -q is intended for purposes like this)
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problem with drivers

Post by Karlosoft »

Thank you for the reply but at the end, I have found a better solution: a function compares two binary linked with a different address, one with the starting point at 0 and the other at 0x11111111 for example. Than it finds the differences and there change the addresses 32bit with the new. Than the new driver is loaded at the location of memory decided. An other similar way is to provide a list of address-loca in order to perform the space used on floppy (with a little more work for the cpu).

Known issues of this way:
  • Align could cause problems because some bytes of the address will be the same.
    I need two copies of the same driver.
    It works only with 32bit addresses.
I'm going to post here the -tiny- program if you want to test it :)
Selenic
Member
Member
Posts: 123
Joined: Sat Jan 23, 2010 2:56 pm

Re: Problem with drivers

Post by Selenic »

Karlosoft wrote:Thank you for the reply but at the end, I have found a better solution
How is a hacky, unreliable (due to alignment), time-consuming (requiring two links rather than one) method of getting data better than asking ld to provide it for you in a well-documented, easy-to-use format? Everything after that collection step is the same whatever you do, anyway.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problem with drivers

Post by Karlosoft »

No It isn't, I mean, the driver loader will found a file linked with all the addresses with org 0 and than an other file that is a list of all the addresses in the driver. The loader will add the base to the address from 0, copying the driver to its place in memory. No other files are required, the two linkages happen when the programmer has to upload a new version :)

I know the problem is the alignment but I will find a way to solve it :). Porting the ld utility is too hard for an os without many functions :). When I will port the gcc this problem will be definitely solved :)

I posted the program with a simple code to test it. You have to recompile reallocator because it is too big to fit it in the zip :).
Attachments
example.rar
(2.97 KiB) Downloaded 85 times
Selenic
Member
Member
Posts: 123
Joined: Sat Jan 23, 2010 2:56 pm

Re: Problem with drivers

Post by Selenic »

Karlosoft wrote:No It isn't, I mean, the driver loader will found a file linked with all the addresses with org 0 and than an other file that is a list of all the addresses in the driver. The loader will add the base to the address from 0, copying the driver to its place in memory. No other files are required, the two linkages happen when the programmer has to upload a new version :)

I know the problem is the alignment but I will find a way to solve it :). Porting the ld utility is too hard for an os without many functions :). When I will port the gcc this problem will be definitely solved :)
Ah, that makes more sense; I thought you were doing something different. So you're basically creating flat binary drivers and including a symbol table separately? I suppose it depends on how you're compiling/linking these drivers. Anyway, I don't see why you can't simply use a cross-compiler on your host until you port gcc/ld (after all, you'll need a cross-compiler to port them!)
Post Reply