The Operating System (OS) MicroComputer Engineering OperatingSystem slide 1!

Similar documents
Exceptions and Interrupts

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

EE 457 Unit 8. Exceptions What Happens When Things Go Wrong

What are Exceptions? EE 457 Unit 8. Exception Processing. Exception Examples 1. Exceptions What Happens When Things Go Wrong

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Run time environment of a MIPS program

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

Page 1, 5/4/99 8:22 PM

EEC 483 Computer Organization

Chapter Two MIPS Arithmetic

Learning Outcomes. A high-level understanding of System Calls Mostly from the user s perspective From textbook (section 1.6)

Instruction Set Architecture of MIPS Processor

Traps, Exceptions, System Calls, & Privileged Mode

Learning Outcomes. Understanding of the existence of compiler function calling conventions Including details of the MIPS C compiler calling convention

EE 109 Unit 17 - Exceptions

Exam in Computer Engineering

Chapter loop: lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1) addi $a0, $a0, 1 addi $a1, $a1, 1 bne $v1, $zero, loop

Anne Bracy CS 3410 Computer Science Cornell University

MIPS Functions and the Runtime Stack

Lecture 11: Interrupt and Exception. James C. Hoe Department of ECE Carnegie Mellon University

MIPS R2000 Assembly Language (Procedure Call, Interrupt, IO, Syscall) CS 230

CS 61c: Great Ideas in Computer Architecture

Anne Bracy CS 3410 Computer Science Cornell University

Inequalities in MIPS (2/4) Inequalities in MIPS (1/4) Inequalities in MIPS (4/4) Inequalities in MIPS (3/4) UCB CS61C : Machine Structures

Learning Outcomes. System Calls. System Calls. The System Call Interface: A Brief Overview. System Calls. The Structure of a Computer System

System Calls. Interface and Implementation

LECTURE 10. Pipelining: Advanced ILP

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Assembly Language Programming

Learning Outcomes. Understanding of the existence of compiler function calling conventions Including details of the MIPS C compiler calling convention

MIPS Assembly Programming

ECE 15B Computer Organization Spring 2010

What is a Process? Answer 1: a process is an abstraction of a program in execution

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

CS 61c: Great Ideas in Computer Architecture

The Operating System and the Kernel

Computer Architecture. The Language of the Machine

Five classic components

CS152 Computer Architecture and Engineering

System Calls. COMP s1

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

CS61C : Machine Structures

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Interrupts Peter Rounce - room 6.18

Lecture 7: Procedures

We will study the MIPS assembly language as an exemplar of the concept.

INSTRUCTION SET COMPARISONS

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CS61c MIDTERM EXAM: 3/17/99

CS 316: Procedure Calls/Pipelining

MIPS Functions and Instruction Formats

Virtual Machines & the OS Kernel

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

EE 109 Unit 15 Subroutines and Stacks

Reduced Instruction Set Computer (RISC)

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Reduced Instruction Set Computer (RISC)

COMPUTER ORGANIZATION AND DESI

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Instructions: Language of the Computer

CS61C : Machine Structures

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Lec 10: Assembler. Announcements

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

COMP I/O, interrupts, exceptions April 3, 2016

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Quiz for Chapter 2 Instructions: Language of the Computer3.10

CS61C : Machine Structures

Computer Systems and Architecture

HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b;

This section covers the MIPS instruction set.

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

MIPS History. ISA MIPS Registers

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Virtual Machines & the OS Kernel

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

Initial Representation Finite State Diagram. Logic Representation Logic Equations

MIPS Hello World. MIPS Assembly 1. # PROGRAM: Hello, World! # Data declaration section. out_string:.asciiz "\nhello, World!\n"

ECE260: Fundamentals of Computer Engineering

What is a Process? Answer 1: a process is an abstraction of a program in execution

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

CS61C : Machine Structures

Instruction Set Architectures (4)

There are different characteristics for exceptions. They are as follows:

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Review: Program Execution. Memory program code program data program stack containing procedure activiation records

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

UCB CS61C : Machine Structures

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

Computer Architecture Experiment

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

ECE 313 Computer Organization FINAL EXAM December 13, 2000

Virtual Machines & the OS Kernel

Transcription:

The Operating System (OS) MicroComputer Engineering OperatingSystem slide 1!

The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 2!

The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 3!

The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 4!

The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 5!

The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 6!

Our Assembler User!.text!.data! Kernel!.ktext!.kdata! MicroComputer Engineering OperatingSystem slide 7!

The Hardware User!.text!.data! ERROR!! Kernel!.ktext!.kdata! OK! MicroComputer Engineering OperatingSystem slide 8!

How does the User program pass control to the Operating System? Take control on ERROR! Pass control explicitly! MicroComputer Engineering OperatingSystem slide 9!

ERROR Ex, Arithmetical Overflow! li $4 0x80000000 neg $4 $4 (sub $4 $0 $4) 0x00000000-0x80000000 0x80000000 Sign differs! Same Sign! ERROR! MicroComputer Engineering OperatingSystem slide 10!

Signed/Unsigned Arithmetics The only difference is that! Unsigned never causes ERROR! Signed causes ERROR on Overflow etc.! Signed!! ADD! SUB! ADDI!..!! Unsigned!! ADDU! SUBU! ADDIU!..!! MicroComputer Engineering OperatingSystem slide 11!

Memory Error Instruction Memory = Bad PC! Data Alignment Error! Access Protected Memory from User mode! Nonexistent Memory! (Page fault Chapter 7)! MicroComputer Engineering OperatingSystem slide 12!

Do not confuse! A Memory that tells the pipeline to Wait! relate to cache miss! A Memory Error or Page Fault! relate to TLB miss, more about that later! MicroComputer Engineering OperatingSystem slide 13!

The Consequence A Memory that tells the pipeline to Wait! Pipeline Stall! A Memory Error or Page Fault! Exception! MicroComputer Engineering OperatingSystem slide 14!

Pass Control Explicitly The User wants some service from the Operating System! File I/O! Graphics! Sound! Allocate Memory! Terminate Program (no HALT instruction in real MIPS)! SYSCALL (causes an exception)! MicroComputer Engineering OperatingSystem slide 15!

How to choose service: Is there different SYSCALLs?! NO! Only one, use a register ($a0) to choose! Use other registers ($a1,...) as parameters! Use $v0 for result ori $a1 $r0 A ; Char A ori $a0 $r0 0x00 ; Write Char syscall ori $a0 $r0 0x01 ; Read Char syscall or $a1 $r0 $v0 ; Move result $v0->$a1 ori $a0 $r0 0x00 ; Echo Char syscall MicroComputer Engineering OperatingSystem slide 16!

Other ways for the Operating System to take control? External Interrupts, (not caused by User program)! Timers! Harddisk! Graphics! Sound! Keyboard, Mouse, other perhipals! MicroComputer Engineering OperatingSystem slide 17!

Coprocessor CP0 8 Bad Memory Address! 12 Status Register! 13 Cause Register! 14 Exception Address (EPC)! MicroComputer Engineering OperatingSystem slide 18!

Status Register CP0 ($12) Mode Stack! External Interrupt enable/disable! MicroComputer Engineering OperatingSystem slide 19!

Mode Stack OLD! PREVIOUS! CURRENT! 5! 0! KU IE! KU IE! KU IE! KU!!! IE! 0 Kernel Mode! 1 User Mode!! 0 External Interrupt Disable! 1 External Interrupt Enable! MicroComputer Engineering OperatingSystem slide 20!

Exception / Interrupt Occurs OLD! PREVIOUS! CURRENT! KU IE! KU IE! KU IE! KU IE! KU IE! 0 0! KU!!! IE! 0 Kernel Mode! 1 User Mode!! 0 External Interrupt Disable! 1 External Interrupt Enable! MicroComputer Engineering OperatingSystem slide 21!

RFE Instruction (priviliged) OLD! PREVIOUS! CURRENT! KU IE! KU IE! KU IE!??! KU IE! KU IE! We restore the PREVIOUS (KU,IE) into CURRENT! MicroComputer Engineering OperatingSystem slide 22!

External Interrupts Bit 0, (Current Interrupt Enable)! All External Interrupts Enable/ Disable! Bit 15..10, (individual interrupt enable)! 15! 10! 0! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! Current! IE!...! MicroComputer Engineering OperatingSystem slide 23!

Enable External Interrupt 2 Bit 0 = 1, (External Interrupt Enabled)! Bit 12 = 1, Interrupt 2 Enabled! 15! 10! 0! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! 0! 0! 0! 1! 0! 0!...! Current! IE = 1! MicroComputer Engineering OperatingSystem slide 24!

Cause Register (CP0 $13) Bit 5..2, Exception Cause Code! Bit 15..10, Interrupt Pending! Bit 31, Exception Occur In Branch Slot! 31! 15! 10! 5! 2! BS! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! Ex 3! Ex 2! Ex 1! Ex 0!...!...!...! Pending Interrupts! Exception Cause Code! see LSI Logic User s Manual! MicroComputer Engineering OperatingSystem slide 25!

Check if Interrupt 2 Pending Mask with bit 12! 15! 10! CP0 $13! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! AND! 0! 0! 0! 1! 0! 0! 0! 0! 0! INT 2! 0! 0! MicroComputer Engineering OperatingSystem slide 26!

Resume User Program! CP0 $14 Holds the Exception Address! (Addr to instruction in EX stage)! mfc0 $k0 $14 ; resume address jr $k0 ; $k0 kernel reg rfe ; delayed branch MicroComputer Engineering OperatingSystem slide 27!

Shared Stack Assume that the User program uses the stack:! Can the Kernel use the same stack ($sp)?!! Yes, but remember never to use memory below $sp, it will be destroyed (overwritten)!!! $sp! User Data! User Data! $sp! Kernel Data! Kernel Data! User Data! User Data! MicroComputer Engineering OperatingSystem slide 28!