From 942fc31c4ffbd341fe82748e6d0a0acd3d36e79a Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 2 Mar 2023 19:07:30 +0100 Subject: [PATCH] docs: documented ELF loading / segment mapping --- .wiki/Kernel-documentation.md | 56 +++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/.wiki/Kernel-documentation.md b/.wiki/Kernel-documentation.md index a980315..038357f 100644 --- a/.wiki/Kernel-documentation.md +++ b/.wiki/Kernel-documentation.md @@ -299,12 +299,14 @@ More information can be found on the limine project's [GitHub](https://github.co #### `elf_executable_T` - struct This struct holds the parsed data of an ELF executable. -| Name | Type | Description | -|--------------|--------------|----------------------------------------------------------------------------------------------------------------------------------| -| header | elf_header_T | The header of the elf file | -| num_symbols | uint64_t | The size of _symbols_ | -| symbols | symbol_T* | An array containing all symbols of the elf file | -| string_table | void* | A copy of the elf files `.strtab` section, all strings are referenced here to have them available even if the elf file is closed | +| Name | Type | Description | +|--------------|----------------|----------------------------------------------------------------------------------------------------------------------------------| +| header | elf_header_T | The header of the elf file | +| num_symbols | uint64_t | The size of _symbols_ | +| symbols | symbol_T* | An array containing all symbols of the elf file | +| num_mappings | uint64_t | The size of _mappings_ | +| mappings | elf_mapping_T* | An array containing the mappings needed to load the elf file | +| string_table | void* | A copy of the elf files `.strtab` section, all strings are referenced here to have them available even if the elf file is closed | #### `elf_executable_temp_T` - struct This struct is used while generating an `elf_executable_T`. @@ -384,6 +386,22 @@ Holds the parsed kernel executable. This will be removed, when processes are implemented, because then this can be accessed via the kernel process control struct. +### elf/mapping.h +#### `elf_mapping_T` - struct +A mapping describes an area of memory, +that should be copied from the elf file into the RAM and how/where it should be mapped. + +| Name | Type | Description | +|----------------|----------|------------------------------------------------------------------------------------------------------------------| +| offset_file | uint64_t | The mappings' start in the elf file | +| offset_virtual | uint64_t | The mappings' start in memory | +| length_file | uint64_t | The mappings' size in the elf file | +| length_virtual | uint64_t | The mappings' size in memory, if this is bigger than _length_file_ the remaining space will be filled with zeros | + +#### `elf_mappings_apply(mappings, num_mappings, buffer, base, page_map)` - function (void) +Maps all **_mappings_** into **_page_map_** and copies the related data from **_buffer_** (elf file) to the mapped memory. +**_base_** specifies where the mappings should start in the virtual address space. + ### elf/section.h #### `elf_section_type_E` - enum - **Null** - These sections can be ignored @@ -415,6 +433,32 @@ This will be removed, when processes are implemented, because then this can be a #### `g_elf_section_type_strings` - global variable An array of strings matching `elf_section_type_E`. +### elf/segment.h +#### `elf_segment_type_E` - enum + - **Null** - Unused segment + - **Load** - Segment that should be included into mappings + - **Dynamic** - Segments of this type contain dynamic linking information + - **Interpreter** - This holds a path to an interpreter + - **Note** - These segments hold notes by the compiler / toolchain + - **Program Header Table** - This points to the table that is holding the segment headers + - **TLS** - This holds a Thread Local Storage template + +#### `elf_segment_T` - struct + +| Name | Type | Description | +|------------------|----------|-----------------------------------------------------------------| +| type | uint32_t | The segments type -> `elf_segment_type_E` | +| flags | uint32_t | The segments flags (Read / Write / Execute) | +| offset | uint64_t | The segments position in the elf file | +| address_virtual | uint64_t | Where the segment should be mapped in the virtual address space | +| address_physical | uint64_t | Not used in the `System V` ABI | +| length_file | uint64_t | The segments size in the file | +| length_memory | uint64_t | The size of the area that should be mapped for the segment | +| align | uint64_t | The segments alignment (has to be a power of 2) | + +#### `g_elf_segment_type_strings` - global variable +An array of strings matching `elf_segment_type_E`. + ### elf/symbol.h #### `ELF_SYMBOL_TYPE(info)` - macro Extracts the `elf_symbol_type_E` from the symbols info value.