ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

Similar documents
Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

Assembly Language: Function Calls" Goals of this Lecture"

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls

CS61 Section Solutions 3

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Process Layout and Function Calls

X86 Stack Calling Function POV

Processes (Intro) Yannis Smaragdakis, U. Athens

x86 architecture et similia

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Machine-level Programming (3)

CSC369 Lecture 2. Larry Zhang, September 21, 2015

CSC369 Lecture 2. Larry Zhang

CS213. Machine-Level Programming III: Procedures

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017

Register Allocation, iii. Bringing in functions & using spilling & coalescing

Machine-Level Programming III: Procedures

Compiler Construction D7011E

CSE 351: Week 4. Tom Bergan, TA

CPS104 Recitation: Assembly Programming

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

System Programming and Computer Architecture (Fall 2009)

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

CS 318 Principles of Operating Systems

Program Exploitation Intro

Intro to Threads. Two approaches to concurrency. Threaded multifinger: - Asynchronous I/O (lab) - Threads (today s lecture)

3. Process Management in xv6

Instruction Set Architecture

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

Week 11 Programmable Interrupt Controller

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

W4118: PC Hardware and x86. Junfeng Yang

CS429: Computer Organization and Architecture

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Machine-Level Programming II: Control and Arithmetic

ASSEMBLY III: PROCEDURES. Jo, Heeseung

Lecture-51 INTEL 8259A Programmable Interrupt Controller

Assembly III: Procedures. Jo, Heeseung

COMP 210 Example Question Exam 2 (Solutions at the bottom)

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Misc. Notes. In BVT, switch from i j only if E j E i C/w i. In BVT, Google is example of W better then L. For lab, recall PDE and PTE bits get ANDed

Systems I. Machine-Level Programming V: Procedures

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

Ausgewählte Betriebssysteme. Anatomy of a system call

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2016 Lecture 12

CS 318 Principles of Operating Systems

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

x86 assembly CS449 Fall 2017

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS241 Computer Organization Spring Addresses & Pointers

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

Section 4: Threads and Context Switching

Machine Program: Procedure. Zhaoguo Wang

CSC 2400: Computing Systems. X86 Assembly: Function Calls

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

W4118: interrupt and system call. Junfeng Yang

Precept 2: Non-preemptive Scheduler. COS 318: Fall 2018

Instructor: Alvin R. Lebeck

+ Overview. Projects: Developing an OS Kernel for x86. ! Handling Intel Processor Exceptions: the Interrupt Descriptor Table (IDT)

Lab 10: Introduction to x86 Assembly

Lecture 4 CIS 341: COMPILERS

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Instruction Set Architecture

Instruction Set Architecture

You may work with a partner on this quiz; both of you must submit your answers.

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Mechanisms for entering the system

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Sungkyunkwan University

CIT Week13 Lecture

Reverse Engineering Low Level Software. CS5375 Software Reverse Engineering Dr. Jaime C. Acosta

The Hardware/Software Interface CSE351 Spring 2013

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Spring 2015

16.317: Microprocessor Systems Design I Fall 2015

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

Machine Programming 3: Procedures

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CSE 153 Design of Operating Systems

X86 Assembly -Procedure II:1

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE 153 Design of Operating Systems Fall 18

CS , Fall 2004 Exam 1

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

Machine Level Programming II: Arithmetic &Control

CS 537 Lecture 2 - Processes

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

CPEG421/621 Tutorial

Instruction Set Architecture

Transcription:

ECE 391 Exam 1 Review Session - Spring 2018 Brought to you by HKN

DISCLAIMER There is A LOT (like a LOT) of information that can be tested for on the exam, and by the nature of the course you never really know what you ll be tested on. We re basing this review session off of the poll on Piazza to help you guys with the material that will most likely be on the exam, but there is a large possibility that there you will be tested on material we do not cover. Please be advised that you should still go over material on your own, and go to office hours to get TAs to help you.

x86 - Brief Overview (Reference sheet is included on the exam) $LABEL - literal value, LABEL - memory address leal LABEL, %edx == movl $LABEL, %edx Can t have more than one memory access per instruction e.g. movl (%eax), (%ebx) Memory is stored little-endian Comparisons signed: jl (lower), jg (greater) unsigned: jb (below), ja (above) cmpl %esi, %edi; jge LABEL Performs the (signed) comparison %edi %esi

x86/c Calling Conventions function(arg1, arg2, arg3): local variables Caller save registers - EAX, ECX, EDX Callee save registers - EBX, ESI, EDI call vs jump: jump jmp LABEL call pushl %eip; jmp LABEL enter - pushl %ebp; movl %esp, %ebp creates the stack frame leave - movl %ebp, %esp; popl %ebp tears down the stack frame ret - popl %eip Push arguments from right to left (why?) *We ll go over a translation question later Callee Save New EBP Stack Frame Call to function Function Args Caller Save %edi %esi %ebx %ebp (old) %eip (return address) arg1 arg2 arg3 %edx %ecx %eax

Synchronization Part 1 - Sharing data structures between program and interrupt handlers - Linked list example

Synchronization Part Dos volatile int ready = 0; while(!ready);

Synchronization Part III - Critical sections code that runs without being interrupted - For single processor machines, use the interrupt flag to accomplish this (drawbacks to using this) - For multiprocessors, we need more: - Introducing...the SPIN LOCK - spin_lock doesn t push the flags to the stack before entering critical section - spin_lock_irqsave pushes the flags before entering critical section - Both however clear the IF flag (why?)

Synchronization Part IV - Semaphores - Up/Down operations - Process goes to sleep giving other processes access to the CPU - Can be used to protect longer critical sections - Reader/Writer Spinlocks - Can cause writer starvation - Reader/Writer Semaphores - Helps prevent starvation

Synchronization Example Problem There is a laboratory which can be occupied by either zombies or scientists. Now you are hired to design a system that satisfies the following rules: At all times, the lab must either be empty, contain scientists, or contain zombies. At most 10 zombies or 4 scientists can stay in the lab, but there is NO limit for the number of zombies/scientists waiting in line. If there are scientists occupying the lab, zombies must wait for all scientists to leave before entering. Similarly, if zombies occupy the lab, scientists must wait for them to leave before they can enter. While waiting in line, scientists have higher priority. This means that if there are scientists waiting to enter, no zombie can enter the lab (even if the lab is currently occupied by zombies). You can think of this as scientists always being moved to the front of the line. Note that when a scientist joins the line and the lab is occupied by zombies, the scientist still must wait for the zombies in the lab to leave; scientists cannot force zombies out of the lab. There is no need to enforce priority among zombies or among scientists (ie. if A arrives before B, A does not necessarily enter the lab before B) When zombies occupy the lab, they introduce contamination. To avoid contaminating the scientists work, the lab must be sanitized before scientists can enter a lab previously occupied by zombies. No sanitization need be done when switching from scientists to zombies. Sanitization must be done as infrequently as possible, and must only be done when the lab is empty. You are to implement a thread safe synchronization library to enforce the lab occupancy policy described above.

Example Problem Continued - A set of enter functions will be called by scientists and zombies to enter the lab. These functions should behave like a lock, and do not return until the lab has been successfully entered by the caller. If any errors occur, return -1. Otherwise, return 0. - When a scientist or zombie wants to leave the lab, they call their leave function to let your library know they have left. - You may use only one spinlock in your design, and no other synchronization primitives may be used. - As these functions will be part of a thread safe library, they may be called simultaneously - Write the code for enter and exit of scientist/zombie. Assume that these functions may be called simultaneously from multiple threads.

Interrupts, Exceptions, System Calls, and Tables! These guys interrupt the regular flow of a program, and are used to: - Deal with something that requires urgent attention now (interrupt). This can usually be masked if we don t wanna (or can t) deal with that stuff. - Tell us what to do when unexpected bad stuff happens (exception) - Let the kernel, higher-privileged code, execute some instruction or carry out some task for us that we can t do ourselves (system call/trap) Every time we get an interrupt, exception, or system call, we jump to a 256-entry vector table called the Interrupt Descriptor Table (IDT) to handle them. You can find the table in lecture slides/notes. - Entries in the table from 0x00-0x1F are reserved and defined by Intel, more later in course - Single entry (0x80) for all system calls. Privilege and stuff matters here, more later in course

Programmable Interrupt Controller Useful for handling multiple interrupts from different devices, can t just stick all the interrupts onto a single bus and expect that to work. The PIC allows us to prioritize, mask, and individually address different interrupts that get raised. - Each PIC handles 8 interrupts, but they can be configured in a master-slave configuration (with one master, and up to 8 other slaves) to handle up to 64 different interrupts. Next slides will go more in-depth - After the processor (our point of view) receives an interrupt from the PIC, it calls ack(nowledge) function to acknowledge receipt and masks all lower-priority interrupts, immediately sends an End-Of-Interrupt (EOI), then calls end function when done handling the interrupt to unmask lower-priority interrupts. - This lets interrupts continue to build up in a queue so we can handle them later.

PIC Functionality Memory mapped to two ports Command port (e.g. 0x20) Data port (MUST be Command Port + 1) CPU - PIC Signals INTR - Activated by the PIC upon interrupt INTA - Pulsed by the CPU whenever D - Bidirectional communication between CPU and PIC Used in programming the PIC, sending EOI, etc. PIC Specific Signals A - Distinguishes Command/Data port on PIC Can be directly mapped to ADDR[0] (why?) CS - Determines whether the given PIC should be active Checks if ADDR[31:1] == PORT[31:1] Priority: IR0, IR1, IR2,, IR7

PIC Cascading (i.e. Master/Slave configuration) Two Level Hierarchy SP - Decides whether a PIC is master or slave 1 = Master, 0 = Slave CAS - How master PIC decides the slave Width is determined by number of slaves the PIC can support (basically the number of IR lines) Given this info, why must it be a two-level hierarchy? If a slave is attached, put all its priorities on the level where it s connected e.g. slave on IR3, the total hierarchy is M0, M1, M2, S0, S1, S2,, S7, M4,, M7

PIC Initialization (1/2) 5 Key steps Lock and save flags (context) so you can initialize properly Mask interrupts to the PIC so you don t get disturbed while initializing Initialize PIC Unmask interrupts Unlock and restore flags

PIC Initialization (2/2) How to actually initialize PIC? All you need to do is send 4 control words! But what do they mean? CONTROL WORD 1: Put PIC in initialization MODE (after this it expects the next 3 control words to come to it on a particular port) CONTROL WORD 2: Tell PIC the start of IDT mapping CONTROL WORD 3: Master: bitmap of slaves; Slave: input pin on master CONTROL WORD 4: Some EOI stuff

More About Interrupts! Interrupt Chaining: - Don t you wish you could handle multiple things when you get an interrupt, well now you can! - With interrupt chaining, multiple handlers can be triggered by one interrupt - Several ways to do this, but generally doesn t happen to often in practice. Soft Interrupts (tasklets): - It s not good to take too much time in a hardware interrupt handler- other interrupts may need to do things too! That s what software interrupts are for - Software interrupts operate at priority level between regular programs and hardware interrupts, so hardware interrupts can generate a software interrupt to handle more time-intensive tasks, allowing other hardware interrupts to interrupt the software interrupts

Anything else??