Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder.

Slides:



Advertisements
Similar presentations
CS 4284 Systems Capstone Godmar Back Processes and Threads.
Advertisements

Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
The ‘system-call’ interface We see how an application program can invoke privileged kernel services.
Context Switch Animation Another one by Anastasia.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
OS Spring’03 Introduction Operating Systems Spring 2003.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Hardware Support for Operating Systems Sunny Gleason Vivek Uppal COM S 414
OS Spring’04 Introduction Operating Systems Spring 2004.
Computer System Laboratory
Intel IA32 OS Support -Refresh
6.828: PC hardware and x86 Frans Kaashoek
Y86 Processor State Program Registers
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
CONTENTS INTRODUCTION to SYSTEM CALLS FUNCTION vs SYSTEM CALL TYPES and EXAMPLES ERRORS and SYSVECTORS HOW DO ALL THESE WORK TOGETHER ADDING A SYSCALL.
CSC 2405 Computer Systems II Exceptions Mini-Lecture Traps & Interrupts.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16.
1 ICS 51 Introductory Computer Organization Fall 2009.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
CS552 Overview © 2009, D. J. Foreman1. Generalized O/S structure Basic interrupt handler – Determines cause – Uses branch table to specific handler I/O.
Exceptional Control Flow Topics Exceptions except1.ppt CS 105 “Tour of the Black Holes of Computing”
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
Functions/Methods in Assembly
6. HAL and IDT ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section  Hardware Abstraction Layer ◦ Section
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
1 Assembly Language: Function Calls Jennifer Rexford.
Lecture 7 Interrupt ,Trap and System Call
Interrupts and Exceptions 國立中正大學 資訊工程研究所 羅習五 老師. Interrupt & Exceptions Interrupts – maskable & nonmaskable interrupt Exceptions – Processor-detected.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Virtualizing the CPU: Processes 1. How to provide the illusion of many CPUs? CPU virtualizing – The OS can promote the illusion that many virtual CPUs.
Exceptional Control Flow
CS 3214 Computer Systems Lecture 9 Godmar Back.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Linux Kernel Development - Robert Love
Memory Management Paging (continued) Segmentation
Microprocessor and Assembly Language
Operating Systems Engineering
Exceptional Control Flow
Microprocessor Systems Design I
IA32 Processors Evolutionary Design
Exceptional Control Flow
Anton Burtsev February, 2017
Protection of System Resources
Exceptional Control Flow
Anton Burtsev February, 2017
Homework Reading Labs S&S Extracts ,
Homework Reading Machine Projects Labs PAL, pp ,
Exceptional Control Flow
Aaron Miller David Cohen Spring 2011
Computer Architecture
Basic Microprocessor Architecture
Recitation 2 – 2/4/01 Outline Machine Model
Exceptional Control Flow: System Calls, Page Faults etc.
Chapter 3 Machine-Level Representation of Programs
Computer Architecture adapted by Jason Fritts then by David Ferry
Y86 Processor State Program Registers
Memory Management Paging (continued) Segmentation
Machine-Level Programming 2 Control Flow
Assembly Language Programming II: C Compiler Calling Sequences
Discussions on HW2 Objectives
System Calls David Ferry CSCI 3500 – Operating Systems
Discussions on HW2 Objectives
Chapter 3 Machine-Level Representation of Programs
Memory Management Paging (continued) Segmentation
Credits and Disclaimers
Interrupts and System Calls
Presentation transcript:

Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder

Overview System Calls System Calls Intel Architecture (IA-32) Support for Interrupts and System Calls Intel Architecture (IA-32) Support for Interrupts and System Calls System Calls in Linux System Calls in Linux Interrupts in Linux Interrupts in Linux

System Calls A system call is the mechanism used by an application program to request service from the operating system. A system call is the mechanism used by an application program to request service from the operating system. Some common examples of system calls available in Linux are: Some common examples of system calls available in Linux are: read, write, open, close, kill or fork read, write, open, close, kill or fork

IA-32 Feature Support for Operating System Development Memory management Memory management Protection of software modules Protection of software modules Multitasking Multitasking Multiprocessing Multiprocessing Cache management Cache management Hardware resource and power management Hardware resource and power management Debugging and performance monitoring Debugging and performance monitoring Exception and interrupt handling Exception and interrupt handling

IA-32 Support for Interrupts & System Calls (1) Interrupts Interrupts Intel 286 Processor (1982) Intel 286 Processor (1982) Privilege levels protect the operating system from: Privilege levels protect the operating system from: Malicious code Malicious code Careless code Careless code Intel offers privilege levels 0-3 Intel offers privilege levels 0-3 Backward compatibility Backward compatibility

IA-32 Support for Interrupts & System Calls (2) 2 Types of Interrupts: 2 Types of Interrupts: External hardware interrupts External hardware interrupts Software Interrupts Software Interrupts Gates provide needed flexibility Gates provide needed flexibility 4 Types of Gates: 4 Types of Gates: Call gates Call gates Interrupt gates Interrupt gates Trap gates Trap gates Task gates Task gates Interrupt Descriptor Table (IDT) Interrupt Descriptor Table (IDT)

Gateways Between High and Low Privileged Code

Interrupt and Trap Gate Descriptors

Using IA-32 Interrupts Interrupt Vectors Interrupt Vectors Index into IDT Index into IDT Value of (0-31 are reserved) Value of (0-31 are reserved) Hardware Interrupts Hardware Interrupts Software Interrupts (relevant instructions) Software Interrupts (relevant instructions) INT n (most important to system calls in Linux) INT n (most important to system calls in Linux) INTO INTO INT 3 INT 3 BOUND BOUND

System Calls in Linux (1) 1. Initialization  Trap_init() is executed within the rest_init() function in init/main.c  Setup_idt() is called from startup_32() in /arch/i386/kernel/head.S 2. Invocation of system call in program 3. Call to library 4. SyscallX (include/asm/unistd.h)

Generic Macro #define _syscall1(type,name,type1,arg1) \ type name(type1 arg1) \ { \ long __res; \ __asm__ volatile ("int $0x80" \ : "=a" (__res) \ : "0" (__NR_##name),"b" ((long)(arg1))); \ if (__res >= 0) \ return (type) __res; \ errno = -__res; \ return -1; \ }

Example Call & Macro Expansion into Assembly _syscall1(int,chdir,char*,path);_chdir: subl $4,%exp subl $4,%exp pushl %ebx; save address pushl %ebx; save address movzwl 12(%esp),%eax; prepare parameters movzwl 12(%esp),%eax; prepare parameters movl %eax,4(%esp) movl %eax,4(%esp) movl $23,%eax movl $23,%eax movl 4(%esp),%ebx movl 4(%esp),%ebx int $0x80; software interrupt changes to kernel mode and jumps to handler int $0x80; software interrupt changes to kernel mode and jumps to handler movl %eax,%edx movl %eax,%edx testl %edx,%edx; check for error testl %edx,%edx; check for error jge L2; if no error, go to L2 jge L2; if no error, go to L2 negl %edx negl %edx movl %edx,_errno movl %edx,_errno movl $-1,%eax movl $-1,%eax popl %ebx popl %ebx addl $4,%esp addl $4,%esp ret ret L2: L2: movl %edx,%eax; clean up movl %edx,%eax; clean up popl %ebx popl %ebx addl $4,%esp addl $4,%esp ret; return ret; return

Each System Call Has a Unique ID From linux/include/linux/unistd.h: From linux/include/linux/unistd.h: #define __NR_chdir 12 #define __NR_time 13 #define __NR_mknod 14 #define __NR_chmod 15

INT 0x80 Interrupts the Kernel.align 4 _system_call: pushl %eax; save orig_eax SAVE_ALL movl $-ENOSYS,EAX(%esp) cmpl $(NR_syscalls),%eax jae ret_from_sys_call movl _sys_call_table(,%eax,4),%eax testl %eax,%eax je ret_from_sys_call movl _current,%ebx andl $~CF_MASK,EFLAGS(%esp); clear carry - assume no errors movl $0,errno(%ebx) movl %db6,%edx movl %edx,dbgreg6(%ebx) ; save current hardware debugging status testb $0x20,flags(%ebx) jne 1f call *%eax movl %eax,EAX(%esp); save the return value movl errno(%ebx),%edx negl %edx je ret_from_sys_call movl %edx,EAX(%esp) orl $(CF_MASK),EFLAGS(%esp); set carry to indicate error jmp ret_from_sys_call

Control Finally Transfers asmlinkage int sys_chdir(const char * filename) { struct inode * inode; struct inode * inode; int error; int error; error = namei(filename,&inode); error = namei(filename,&inode); if (error) if (error) return error; return error; if (!S_ISDIR(inode->i_mode)) { if (!S_ISDIR(inode->i_mode)) { iput(inode); iput(inode); return -ENOTDIR; return -ENOTDIR; } if ((error = permission(inode,MAY_EXEC)) != 0) { if ((error = permission(inode,MAY_EXEC)) != 0) { iput(inode); iput(inode); return error; return error; } iput(current->fs->pwd); iput(current->fs->pwd); current->fs->pwd = inode; current->fs->pwd = inode; return (0); return (0);}

Interrupts in Linux Bidirectional communication: Bidirectional communication: Hardware OS Hardware OS Two types of interrupts under Linux: Two types of interrupts under Linux: Short & long Short & long All interrupt handlers perform 5 basic actions: All interrupt handlers perform 5 basic actions: Save IRQ Save IRQ Acknowledge Acknowledge Execute interrupt service routine Execute interrupt service routine Terminate by jumping to ret_from_intr() Terminate by jumping to ret_from_intr() Request_irq() (from linux/arch/i386/kernel/irq.c) Request_irq() (from linux/arch/i386/kernel/irq.c)

Struct irqaction This data structure is found in include/linux/interrupt.h This data structure is found in include/linux/interrupt.h struct irqaction { void (*handler)(int, void *, struct pt_regs *); void (*handler)(int, void *, struct pt_regs *); unsigned long flags; unsigned long flags; unsigned long mask; unsigned long mask; const char *name; const char *name; void *dev_id; void *dev_id; struct irqaction *next; struct irqaction *next;};

Conclusion From it’s earliest processors back to the 16-bit 8086, released in 1978, Intel has had extensive support for hardware and software interrupts. Interrupt features are vital to operating systems. From it’s earliest processors back to the 16-bit 8086, released in 1978, Intel has had extensive support for hardware and software interrupts. Interrupt features are vital to operating systems. The only significant architectural change related to interrupts was the inclusion of the Advanced Programmable Interrupt Controller (APIC) in 1993 on the Intel Pentium. The APIC is used in support of SMP systems. The only significant architectural change related to interrupts was the inclusion of the Advanced Programmable Interrupt Controller (APIC) in 1993 on the Intel Pentium. The APIC is used in support of SMP systems.

References IA-32 Intel Architecture Software Developer’s Manual (volumes 1-3: Basic Architecture, Instruction Set Reference & System Programming Guide) IA-32 Intel Architecture Software Developer’s Manual (volumes 1-3: Basic Architecture, Instruction Set Reference & System Programming Guide) arquitectura/gen-t2-arquitectura.html arquitectura/gen-t2-arquitectura.html htm htm