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

Slides:



Advertisements
Similar presentations
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Advertisements

Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
The Microprocessor and its Architecture
Crafting a ‘boot time’ program How we can utilize some standard ‘real-mode’ routines that reside in the PC’s ROM-BIOS firmware.
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS 9.1 Introduction Application programs are typically developed, compiled, and run on host system Embedded programs.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
CS318 Project #2 Bootup Mechanism.
Interfacing with ELF files
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Linking, Loading and Mapping A look at how Operating System utilities and services support application deployment.
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
Interfacing with ELF files An introduction to the Executable and Linkable Format (ELF) binary file specification standard.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’ for the program-segments in an ELF executable file.
1 Operating Systems and Protection Professor Jennifer Rexford CS 217.
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
8.7 Memory management Program E Program D System memory DOS INT 21, function 48H: Allocate Memory Specification: allocates a number of memory paragraphs.
Executing an ELF executable
40 Advanced Operating Systems Implementing System Calls.
Chapter 3.2 : Virtual Memory
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
An introduction to systems programming
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Executing an ELF executable How to load an executable ELF file for execution in ‘extended’ physical memory.
Embedded Control Systems Introduction to cross development techniques.
On 64-bit ‘code-relocation’ How we can launch a procedure in 64-bit mode that resides in a page-frame at a high address.
A ‘protected-mode’ exploration A look at the steps needed to build segment-descriptors for displaying a message while in protected-mode.
UEE072HM Embedded Control Systems. Breaking down the compilation process Compilation is made up of a number of phases –Preprocessing –Compilation Can.
Structure of DOS application programs. Contents: 1. PSP 2..COM and.EXE 3. TSR: Terminate and Stay Resident Programs.
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Interfacing with ELF files An introduction to the Executable and Linkable Format (ELF) binary file specification standard.
 Contents 1.Introduction about operating system. 2. What is 32 bit and 64 bit operating system. 3. File systems. 4. Minimum requirement for Windows 7.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Eric Keller, Evan Green Princeton University PRESTO /22/08 Virtualizing the Data Plane Through Source Code Merging.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Basic & Advanced Reporting in TIMSNT ** Part Two **
Topic 2d High-Level languages and Systems Software
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
 Virtual machine systems: simulators for multiple copies of a machine on itself.  Virtual machine (VM): the simulated machine.  Virtual machine monitor.
Processes and Virtual Memory
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Segment Descriptor Segments are areas of memory defined by a programmer and can be a code, data or stack segment. In segments need not be all the.
Functions/Methods in Assembly
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
Project 1 Roadmap read the project description ? read the newsgroup ? read the ELF specification ? –( , , ) read the elfHeader correctly.
Sem 2v2 Chapter 5 Router Startup and Setup. A router initializes by loading the bootstrap, the operating system, and a configuration file. If the router.
CSc 453 Linking and Loading
Memory Management 백 일 우
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Instructions for test_function
Basic Paging (1) logical address space of a process can be made noncontiguous; process is allocated physical memory whenever the latter is available. Divide.
143A: Principles of Operating Systems Lecture 7: System boot
Program Execution in Linux
Topic 2e High-Level languages and Systems Software
Loaders and Linkers.
Page Replacement Implementation Issues
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS
Introduction to the Intel x86’s support for “virtual” memory
The Microprocessor & Its Architecture
Program Execution in Linux
Loaders and Linkers.
An introduction to systems programming
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

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

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

8086/8088 addresses 0x23450x9876 0x2CCC6 segment-addressoffset-address + x16 Logical Address Physical Address (20-bits) 0x x x2CCC6

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

Emulating 8086/8088 on Special circuitry provided to ‘disable’ the 21 st 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)

Effect of A20 address-line Extra 64KSame 64K A20 enabled A20 disabled Highest 20-bit address (= 0x0FFFFF) Highest real-mode address (= 0x10FFEF) “extended” memory is above 1MB “conventional” memory is below 1 MB same memory appears at two places memory differs at these places

port 0x92 FAST A20 FAST RESET reset the CPU (1=yes, 0=no) enable A20-line (1=yes, 0=no) # how you can turn on the A20 address-line in$0x92, %al or$0x02, %al out%al, $0x92 (These bits may implement some other system functions, depending on the vendor’s design (not standardized), so beware of modifying them in ‘portable’ system software

Comparing A20 on/off Extended Memory seen by the CPU when A20 is on Extended Memory seen by the CPU when A20 is off 0x x x x x x x x x x x00A00000 Memory-addresses in one-megabyte increments

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

Linker ‘relocates’ addresses ELF Header Section-Header Table Section 1 Data Section 2 Data … Section n Data ELF Header Section-Header Table Section 1 Data Section 2 Data … Section n Data ELF Header Program-Header Table Segment 1 Data Segment 2 Data … Segment n Data Linkable File Executable File

The ‘built-in’ linker script Two main ideas that the linker implements: –It combines identically-named sections of the linkable ELF files into a single segment –It assigns runtime addresses to the resulting program data and program code which are non-conflicting and are suitably aligned It may optionally perform other manipulations, depending on directions in its linker script It uses a built-in linker script if you don’t specify otherwise; you can view it using the command- option:$ ld -verbose

ELF32 File Header ΔELF class type program entry-point PHT file-offset PHT entry size PHT entry count ‘Executable’ or ‘Linkable’ 32-bit or 64-bit PHT = Program-segment Header-Table Initial value for EIP register

PHT entries p_type p_offset p_vaddr p_paddr p_filesz p_memsz p_flags p_align Fields in an ELF32 Program-segment Header Table entry Our ‘elfexec.s’ program-loader uses these highlighted fields to simulate program-loading (i.e., to initialize the regions in Extended memory which are needed for program execution

In-Class demo Suppose we want to execute ‘linuxapp’ using our own custom OS environment Boot-disk preparation steps: $ as –32 linuxapp.s –o linuxapp.o $ ld –melf_i386 linuxapp.o –o linuxapp $ dd if=linuxapp of=/dev/sda4 seek=65 We’ll need modifications to our ‘tryelf32.s’

The two program-segments When used without any linker script, our GNU linker-utility (‘ld’) relocates the ‘.text’ and ‘.data’ and ‘.bss’ program-segments, for residence at specific memory-addreses far above the 1-MB conventional ‘real-mode’ memory-area The memory-address 0x is standard for the relocation of an Elf_32 code-segment So we will need to ‘copy’ some portions of the executable ELF-file’s contents to the specified addresses in ‘Extended’ physical memory

New segment-descriptors We can setup segment-limits of size 4GB using Descriptor Privilege Level (DPL) =3 For our (32-bit) data-segment:.quad 00CFF FFFF# 4GB-data For our (32-bit) code-segment:.quad 00CF7A000000FFFF# 4GB-code Both these segments include all memory It’s useful to mark code as ‘Not Present’

Initial values for ESP and EIP The program’s entry-point is obtained from the.e_entry; field in the ELF-file’s 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

Where’s our ring3 stack?.data.text 0x x Our OS 0x IVT and BDA 0x ESP ring3 stack EIP 0x (at 1-GB).bss

Demos Our ‘elfexec.s’ program demonstrates the simulation of ‘on-demand loading’ for two ‘executable’ ELF32 files on our website: –‘linuxapp’ (which we’ve used previously) –‘usingbss’ (which illustrates ‘.bss’ loading) Our ‘elfinfo.cpp’ utility aids in examining an ELF32 files’s PHT entries and entry-point