What Linux does with IDE? Introduction to Pentium features for trapping reads/writes to memory-locations and i/o-ports.

Slides:



Advertisements
Similar presentations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Advertisements

Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
Microprocessors General Features To be Examined For Each Chip Jan 24 th, 2002.
Virtualization Technology A first look at some aspects of Intel’s ‘Vanderpool’ initiative.
Intel MP.
Microprocessor system architectures– IA32 debugging and performance monitoring Jakub Yaghob.
Facilities for x86 debugging
The ‘system-call’ interface We see how an application program can invoke privileged kernel services.
Facilities for x86 debugging Introduction to x86 CPU features that can assist programmers in the debugging of their software.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
The x86 Feature Flags On using the CPUID instruction for processor identification and feature determination.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Facilities for x86 debugging Introduction to Pentium features that can assist programmers in their debugging of software.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
8051 ASSEMBLY LANGUAGE PROGRAMMING
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
CS2422 Assembly Language & System Programming September 26, 2006.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#1) By Dr. Syed Noman.
High-Level Language Interface Chapter 17 S. Dandamudi.
Chapter 2 Software Tools and Assembly Language Syntax.
The Pentium Processor Chapter 3 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
The Pentium Processor Chapter 3 S. Dandamudi.
COMP2011 Assembly Language Programming and Introduction to WRAMP.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
What have mr aldred’s dirty clothes got to do with the cpu
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
UBI >> Contents Chapter 2 Software Development tools Code Composer Essentials v3: Code Debugging Texas Instruments Incorporated University of Beira Interior.
Assembly Language A Brief Introduction. Unit Learning Goals CPU architecture. Basic Assembler Commands High level Programming  Assembler  Machine Language.
System Address Registers/Memory Management Registers Four memory management registers are used to specify the locations of data structures which control.
Assembly תרגול 5 תכנות באסמבלי. Assembly vs. Higher level languages There are NO variables’ type definitions.  All kinds of data are stored in the same.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 ICS 51 Introductory Computer Organization Fall 2009.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Other Processors. Having learnt MIPS, we can learn other major processors. Not going to be able to cover everything; will pick on the interesting aspects.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
CE-2810 Dr. Mark L. Hornick 1 Mixing C and assembly Safety goggles on!
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
Functions/Methods in Assembly
1 The Instruction Set Architecture September 27 th, 2007 By: Corbin Johnson CS 146.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Embedding Assembly Code in C Programs תרגול 7 שילוב קוד אסמבלי בקוד C.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Memory Management Chapter 5 Advanced Operating System.
DR. MIGUEL ÁNGEL OROS HERNÁNDEZ 2. Software de bajo nivel.
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
Introduction to computer software. Programming the computer Program, is a sequence of instructions, written to perform a specified task on a computer.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Assembly language.
IA32 Processors Evolutionary Design
A Closer Look at Instruction Set Architectures
16.317: Microprocessor System Design I
Basic Microprocessor Architecture
High-Level Language Interface
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Assembly Language Programming II: C Compiler Calling Sequences
CS 301 Fall 2002 Computer Organization
MIPS Procedure Calls CSE 378 – Section 3.
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Computer Architecture and System Programming Laboratory
The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language.
Presentation transcript:

What Linux does with IDE? Introduction to Pentium features for trapping reads/writes to memory-locations and i/o-ports

Breakpoint Address Registers DR0 DR1 DR2 DR3

Special ‘MOV’ instructions Use ‘mov DRn, genreg’ to write into DRn Use ‘mov genreg, DRn’ to read from DRn These instructions are ‘privileged’ (i.e., can only be executed by code running in ring0)

Debug Control Register (DR7) 00 GDGD 001 GEGE LELE G3G3 L3L3 G2G2 L2L2 G1G1 L1L1 G0G0 L0L0 LEN 3 R/W 3 LEN 2 R/W 2 LEN 1 R/W 1 LEN 0 R/W Least significant word Most significant word

What kinds of breakpoints? LENR/W LEN 00 = one byte 01 = two bytes 10 = undefined 11 = four bytes R/W 00 = break on instruction fetch only 01 = break on data writes only 10 = break on in/out to port-address ** 11 = break on data reads or writes (but not on instruction fetches) ** Provided the DE-bit (bit 3) is set to 1 in Control Register CR4

Control Register 4 The Pentium uses Control Register 4 to activate certain extended features of the processor, while still allowing for backward compatibility with systems software that was written for earlier x86 processors An example: Debug Extensions (DE-bit) other feature bits CR4 DEDE

Debug Status Register (DR6) BDBD B3B3 B2B2 B1B1 unused ( all bits here are set to 1 ) Least significant word Most significant word BSBS B T 1 B0B0

Where to set a breakpoint Suppose you want to trigger a ‘debug’ fault whenever Linux tries to write/read the IDE Command/Status Register (ioport 0x1F7) Your debug exception-handler can use the saved CS:EIP values on its stack to check whether an ‘out’ or ‘in’ was just executed Machine-code: 0xEC for “ in %dx, %al ”, or 0xEE for “ out %al, %dx ” Could set a ‘breakpoint’ at address EIP-1

Detecting a ‘breakpoint’ Your debug exception-handler reads DR6 to check for occurrences of breakpoints mov eax, DR6; get debug status bt eax, #0; breakpoint #0? jnc notBP0; no, another cause ; test for other causes… notBP0:

The ‘asm’ construct An introduction to the GNU C/C++ compiler’s obscure syntax for doing inline assembly language

The ‘asm’ construct When using C/C++ for systems programs, we sometimes need to employ processor- specific instructions (e.g., to access CPU registers or the current stack area) Because our high-level languages strive for ‘portability’ across different hardware platforms, these languages don’t provide direct access to CPU registers or stack

gcc/g++ extensions The GNU compilers support an extension to the language which allows us to insert assembler code into our instruction-stream Operands in registers or global variables can directly appear in assembly language, like this (as can immediate operands): intcount = 4;// global variable asm(“ movl count, %eax “); asm(“ imull $5, %eax, %ecx “);

Local variables Variables defined as local to a function are more awkward to reference by name with the ‘asm’ construct, because they reside on the stack and require the generation of offsets from the %ebp register-contents A special syntax is available for handling such situations in a manner that gcc/g++ can decipher

Template The general construct-format is as follows: asm( instruction-template : output-operand : input-operand : clobber-list );

Example from ‘hdtraps.c’ void trap_handler( unsigned long *tos ) { unsigned longdb_status; // … other instructions can go here … asm(“ movl %dr6, %eax “); asm(“ movl %eax, %0 “ : “=m” (db_status) ); // … other instructions can go here … }

In-class exercise Modify the ‘hdtraps.c’ module so that the output from ‘/proc/hdtraps’ is improved (i.e., more understandable to humans) Instead of: eax= opn=EC show: 0x50 = inb( 0x01F7 ); Instead of: eax=007402EA opn=EE show:outb( 0xEA, 0x01F7 );