1 / 15

Executing an ELF executable

Executing an ELF executable. How to load an executable ELF file for execution in ‘extended’ physical memory. What is ‘Extended Memory’?. extended memory. 4GB. extended memory. 16MB. conventional memory. conventional memory. conventional memory. 1MB. 8086/8088

skyla
Télécharger la présentation

Executing an ELF executable

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Executing an ELF executable How to load an executable ELF file for execution in ‘extended’ physical memory

  2. What is ‘Extended Memory’? extended memory 4GB extended memory 16MB conventional memory conventional memory conventional memory 1MB 8086/8088 (20-bit addresses) 80286 (24-bit addresses) 80386+ (32-bit addresses)

  3. 8086/8088 addresses segment-address offset-address 0x2345 0x9876 Logical Address x16 + 0x23450 + 0x09876 --------------- 0x2CCC6 0x2CCC6 Physical Address (20-bits)

  4. Biggest 8086/8088 address segment-address offset-address 0xFFFF 0xFFFF Logical Address x16 + 0xFFFF0 + 0x0FFFF --------------- 0x10FFEF 0x0FFEF Physical Address (20-bits) A20

  5. Emulating 8086/8088 on 80286 • Special circuitry provided to ‘disable’ the 21st address-line (named A20) causes addresses to ‘wrap’ at the 1MB boundry • Original IBM-AT used keyboard controller to perform enabling/disabling of A20-line • Newer machines have faster ways to enable/disable A20-line (e.g., port 0x92)

  6. Executable versus Linkable ELF Header ELF Header Program-Header Table (optional) Program-Header Table Section 1 Data Segment 1 Data Section 2 Data Segment 2 Data Section 3 Data Segment 3 Data … Section n Data … Segment n Data Section-Header Table Section-Header Table (optional) Linkable File Executable File

  7. In-Class Exercise • We want to execute the ‘hello’ application in our own operating system environment • Boot-disk preparation steps: $ as hello.s –o hello.o $ ld hello.o –o hello $ dd if=hello of=/dev/fd0 seek=13 • We need modifications to our ‘try32bit.s’

  8. The two program-segments • Our Linker utility (‘ld’) relocates the ‘.text’ and ‘.data’ program-segments for loading at memory-addresses 0x08048000 and 0x08049000, respectively • We will need to copy the contents of these two portions of our executable image-file to these addresses in extended physical memory

  9. New segment-descriptors • We can setup segment-limits of size 4GB using Descriptor Privilege Level (DPL) =3 • For our code-segment: .WORD 0xFFFF, 0x0000, 0xFA00, 0x00CF • For our data-segment: .WORD 0xFFFF, 0x0000, 0xF200, 0x00CF • For our stack-segment: .WORD 0xFFFF, 0x0000, 0xF200, 0x00CF

  10. Loading the ‘.text’ and ‘.data’ • Image-file fits within five Boot-disk sectors (#14-#18), so total size is at most 0x0A00 • So we can copy the entire ELF file-image from address 0x00011800 to 0x08048000 to initialize our ‘.text’ program-segment • And we can copy the entire ELF file-image from address 0x00011800 to 0x08049000 to initialize our ‘.data’ program-segment

  11. Initial values for ESP and EIP • The program’s entry-point is 0x08048074 (as obtained from the file’s ELF Header) • The decision about an initial value for ESP is largely up to us, taking into account the amount of physical memory installed and the regions of memory already being used for other system purposes

  12. Where’s our ring3 stack? .data 0x08049000 EIP .text ESP 0x08048000 ring3 stack OS630 0x00010000 IVT and BDA 0x00000000

  13. In-Class Exercise • Make a copy of our ‘try32bit.s’ demo (from our CS630 course website), and modify it so it will execute the ‘hello’ ELF file-image • The code that transfers control to ‘hello’ would look like this: push dword #userSS ; image for SS push dword #0x08048000 ; image for ESP push dword #userCS ; image for CS push dword #0x08048074 ; image for EIP retf ; execute ‘hello’

  14. Note on avoiding a ‘crash’ • The ‘try32bit.s’ program never modified the upper 16-bits of the ESP register (these 16 bits always remained clear) • But now ESP will be loaded with a value that does modify its upper word • This will cause a problem when attempting to return to the original stack-address, as ‘LSS SP, tossave’ won’t clear upper bits

  15. First step of the Exercise • Change the storage-size for ‘tossave’ from 32-bits to 48-bits, like this: tossave: .WORD 0, 0, 0 • Then change the two instructions that save the stack-pointer, like this: mov tossave+0, esp mov tossave+4, ss • And also change the instruction that reloads the stack-pointer, like this: lss esp, tossave

More Related