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

Slides:



Advertisements
Similar presentations
Register In computer architecture, a processor register is a small amount of storage available on the CPU whose contents can be accessed more quickly than.
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.
Intel MP.
OS Memory Addressing.
CS318 Project #2 Bootup Mechanism.
Lect 3: Instruction Set and Addressing Modes. 386 Instruction Set (3.4) –Basic Instruction Set : 8086/8088 instruction set –Extended Instruction Set :
Linking, Loading and Mapping A look at how Operating System utilities and services support application deployment.
Executing an ELF executable How to load an executable ELF file for execution in ‘extended’ physical memory.
Operating Systems: Segments 1 Segmentation Hardware Support single user program system: – wish somehow to relocate address 0 to after operating system.
Getting Ready to Enter x86 Protected Mode Survival tactics for enabling Protected-Mode with a minimum of supporting infrastructure.
IA-32 Processor Architecture
Interfacing with ELF files An introduction to the Executable and Linkable Format (ELF) binary file specification standard.
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’ for the program-segments in an ELF executable file.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Executing an ELF executable
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.
CS2422 Assembly Language & System Programming September 22, 2005.
A ‘protected-mode’ exploration A look at the steps needed to build segment-descriptors for displaying a message while in protected-mode.
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 4: x86 memory.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Interfacing with ELF files An introduction to the Executable and Linkable Format (ELF) binary file specification standard.
Administrative Overview 6 Projects Design Review: Monday before 6:30pm Lab Friend Center 010 (“Fishbowl”)
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Lect 4: Instruction Set and Addressing Modes. 386 Instruction Set (3.4)  Basic Instruction Set : 8086/8088 instruction set  Extended Instruction Set.
6.828: PC hardware and x86 Frans Kaashoek
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 ICS 51 Introductory Computer Organization Fall 2009.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Functions/Methods in Assembly
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
Page Replacement Implementation Issues Text: –Tanenbaum ch. 4.7.
Chapter 2 The Microprocessor Architecture Microprocessors prepared by Dr. Mohamed A. Shohla.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
BITS Pilani Pilani Campus Pawan Sharma Lecture / ES C263 INSTR/CS/EEE F241 Microprocessor Programming and Interfacing.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Assembly language.
143A: Principles of Operating Systems Lecture 7: System boot
Anton Burtsev February, 2017
8086 Microprocessor.
Computer Organization & Assembly Language Chapter 3
143A: Principles of Operating Systems Lecture 5: Address translation
Aaron Miller David Cohen Spring 2011
Program Execution in Linux
University of Gujrat Department of Computer Science
Page Replacement Implementation Issues
8086 MICROPROCESSOR PROGRAMMING – INTEGER INSTRUCTIONS AND COMPUTATIONS Amar Saraswat.
SAPC Hardware Pentium CPU (or 486) 4M usable memory
CS 301 Fall 2002 Computer Organization
Loaders and Linkers.
Page Replacement Implementation Issues
The Microprocessor & Its Architecture
Computer Architecture CST 250
Loaders and Linkers.
An introduction to systems programming
Intel 8086.
Computer Architecture and System Programming Laboratory
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)

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

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

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

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/sda4 seek=13 We need modifications to our ‘try32bit.s’

The two program-segments When used without any linker script, our linker-utility (‘ld’) relocates the ‘.text’ and ‘.data’ program-segments for loading at the memory-addresses 0x and 0x , respectively So we will need to copy the contents of these two portions of our ELF executable image-file to those 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) code-segment:.word 0xFFFF, 0x0000, 0xFA00, 0x00CF For our (32-bit) data-segment:.word 0xFFFF, 0x0000, 0xF200, 0x00CF For our (32-bit) stack-segment:.word 0xFFFF, 0x0000, 0xF200, 0x00CF

Loading the ‘.text’ and ‘.data’ ELF file-image fits within three disk sectors (#14-#16), so total size is at most 0x0600 So we can copy the entire ELF file-image from address 0x to 0x to initialize our ‘.text’ program-segment And we can copy the entire ELF file-image from address 0x to 0x to initialize our ‘.data’ program-segment

Copying ‘hello’ # copying.text section.code32 mov$sel_FS, %ax mov%ax, %ds mov%ax, %es mov$0x , %esi mov$0x , %edi cld mov$0x800, %ecx repmovsb # copying.data section.code32 mov$sel_FS, %ax mov%ax, %ds mov%ax, %es mov$0x , %esi mov$0x , %edi cld mov$0x800, %ecx repmovsb The ‘hello’ executable ELF file easily fits within 4 hard-disk sectors (= 0x800 bytes)

Initial values for ESP and EIP The program’s entry-point is 0x (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

Where’s our ring3 stack?.data.text 0x x OS630 0x IVT and BDA 0x ESP ring3 stack EIP

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 You’ll need to setup registers TR, DS, and ES Then a code-fragment that will transfer control to ‘hello’ could look like this -- assuming it occurs in a 32-bit code segment: pushl $userSS ; image for SS pushl $0x ; image for ESP pushl $userCS ; image for CS pushl $0x ; image for EIP lret; execute ‘hello’