Point 4 of this outline seems to imply that the drivers has been loaded into physical memory (RAM) but hasn't been relocated with the kernel's address space. If drivers/modules has already been loaded into RAM what is the point of relocating? Why not just link and relocate all the drivers/module with kernel into one executable image during compile time? How does relocating when needed in this case save time if drivers/modules have to be loaded into ram anyways?The basic outline of things you need to do for relocation:
1. Check the object file header (it has to be ELF, not PE, for example)
2. Get a load address (eg. all drivers start at 0xA0000000, need some method of keeping track of driver locations)
3. Allocate enough space for all program sections (ST_PROGBITS)
4. Copy from the image in RAM to the allocated space
5. Go through all sections resolving external references against the kernel symbol table
If all succeeded, you can use the "e_entry" field of the header as the offset from the load address to call the entry point (if one was specified), or do a symbol lookup, or just return a success error code.
question on relocation of drivers and modules
question on relocation of drivers and modules
From reading http://wiki.osdev.org/ELF#Relocation tutorial it seems that relocation is useful when loading drivers and modules. According to the tutorial:
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: question on relocation of drivers and modules
I assume this assumes that the module has been loaded by the boot-loader, and exists somewhere in RAM. It needs to be copied (or sometimes you can use page mapping instead) to expand the rather packed ELF file into the runtime layout (e.g. the file might expect to take up three pages at runtime - one for .text, and another two for .data and a large .bss - but only be stored in the file as less than a page).
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: question on relocation of drivers and modules
Hi,thepowersgang wrote:I assume this assumes that the module has been loaded by the boot-loader, and exists somewhere in RAM. It needs to be copied (or sometimes you can use page mapping instead) to expand the rather packed ELF file into the runtime layout (e.g. the file might expect to take up three pages at runtime - one for .text, and another two for .data and a large .bss - but only be stored in the file as less than a page).
For your OS do you relocate your driver and modules during run time or compile time?
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: question on relocation of drivers and modules
Runtime, because any combination of modules could be loaded at any one time.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc