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

Similar documents
143A: Principles of Operating Systems. Lecture 5: Address translation. Anton Burtsev October, 2018

143A: Principles of Operating Systems. Lecture 6: Address translation. Anton Burtsev January, 2017

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

6.828: Using Virtual Memory. Adam Belay

CS5460/6460: Operating Systems. Lecture 9: First process. Anton Burtsev January, 2014

Processes (Intro) Yannis Smaragdakis, U. Athens

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

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

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls

3. Process Management in xv6

IA32 Intel 32-bit Architecture

Changes made in this version not seen in first lecture:

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

Low Level Programming Lecture 2. International Faculty of Engineerig, Technical University of Łódź

Section 4: Threads and Context Switching

W4118: PC Hardware and x86. Junfeng Yang

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

143A: Principles of Operating Systems. Lecture 7: System boot. Anton Burtsev January, 2017

x86 Assembly Tutorial COS 318: Fall 2017

Microkernel Construction

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

238P: Operating Systems. Lecture 3: Calling conventions. Anton Burtsev October, 2018

143A: Principles of Operating Systems. Lecture 5: Calling conventions. Anton Burtsev January, 2017

143A: Principles of Operating Systems. Lecture 4: Calling conventions. Anton Burtsev October, 2017

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

An Introduction to x86 ASM

4. The Abstraction: The Process

Tutorial 10 Protection Cont.

This is an open book, open notes exam. But no online or in-class chatting.

238P: Operating Systems. Lecture 7: System boot. Anton Burtsev January, 2017

Microkernel Construction

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

This is an open book, open notes exam. But no online or in-class chatting.

x86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT

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

Introduction to IA-32. Jo, Heeseung

143A: Principles of Operating Systems. Lecture 7: System boot. Anton Burtsev October, 2017

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

INTRODUCTION TO IA-32. Jo, Heeseung

CS5460/6460: Operating Systems. Lecture 9: Finishing system boot, and system init. Anton Burtsev January, 2014

COP4610: Operating Systems Project 1

IA32/Linux Virtual Memory Architecture

What You Need to Know for Project Three. Dave Eckhardt Steve Muckle

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

x86 assembly CS449 Fall 2017

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

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

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

Chapter 11. Addressing Modes

X86 Stack Calling Function POV

16.317: Microprocessor Systems Design I Fall 2013

MICROPROCESSOR TECHNOLOGY

Machine-level Programming (3)

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

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Ausgewählte Betriebssysteme. Anatomy of a system call

x86 architecture et similia

Complex Instruction Set Computer (CISC)

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

Program Exploitation Intro

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

CPEG421/621 Tutorial

ICS143A: Principles of Operating Systems. Lecture 14: System calls (part 2) Anton Burtsev November, 2017

CS213. Machine-Level Programming III: Procedures

µ-kernel Construction (12)

Buffer Overflow Attack

CSE 351: Week 4. Tom Bergan, TA

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

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

Quiz I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Department of Electrical Engineering and Computer Science

CMSC 313 Lecture 12 [draft] How C functions pass parameters

Machine Programming 3: Procedures

CPS104 Recitation: Assembly Programming

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

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

The Microprocessor and its Architecture

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

Project 2: Signals. Consult the submit server for deadline date and time

ASSEMBLY III: PROCEDURES. Jo, Heeseung

Process Layout and Function Calls

Assembly III: Procedures. Jo, Heeseung

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

16.317: Microprocessor Systems Design I Fall 2014

Basic Execution Environment

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

CS3210: Booting and x86

Operating Systems Engineering Recitation #3 (part 2): Interrupt and Exception Handling on the x86. (heavily) based on MIT 6.

Mechanisms for entering the system

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

x86 Memory Protec.on and Transla.on

x86 Memory Protec2on and Transla2on

PROTECTION CHAPTER 4 PROTECTION

CS61 Section Solutions 3

Processes and Threads

CS3210: Booting and x86. Taesoo Kim

W4118: interrupt and system call. Junfeng Yang

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Systems I. Machine-Level Programming V: Procedures

Transcription:

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

Describe the x86 address translation pipeline (draw figure), explain stages.

Address translation

What is the linear address? What address is in the registers, e.g., in %eax?

Logical and linear addresses Segment selector (16 bit) + offset (32 bit)

What segments do the following instructions use? push, jump, mov

Programming model Segments for: code, data, stack, extra A program can have up to 6 total segments Segments identified by registers: cs, ds, ss, es, fs, gs Prefix all memory accesses with desired segment: mov eax, ds:0x80 (load offset 0x80 from data into eax) jmp cs:0xab8 (jump execution to code offset 0xab8) mov ss:0x40, ecx (move ecx to stack offset 0x40)

Segmented programming (not real) static int x = 1; ds:x = 1; // data int y; // stack ss:y; if (x) { if (ds:x) { // stack y = 1; ss:y = 1; printf ( Boo ); cs:printf(ds: Boo ); } else y = 0; } else ss:y = 0;

Describe the linear to physical address translation with the paging mechanism (use provided diagram, mark and explain the steps).

Page translation

Page translation

Page directory entry (PDE) 20 bit address of the page table R/W writes allowed? To a 4MB region controlled by this entry U/S user/supervisor Pages 4KB each, we need 1M to cover 4GB If 0 user-mode access is not allowed A accessed

Page translation

Page table entry (PTE) 20 bit address of the 4KB page R/W writes allowed? Pages 4KB each, we need 1M to cover 4GB To a 4KB page U/S user/supervisor If 0 user-mode access is not allowed A accessed D dirty software has written to this page

Page translation

Consider the following 32-bit x86 page table setup. %cr3 holds 0x00001000. The Page Directory Page at physical address 0x00001000: PDE 0: PPN=0x00002, PTE_P, PTE_U, PTE_W PDE 1: PPN=0x00003, PTE_P, PTE_U, PTE_W PDE 2: PPN=0x00002, PTE_P, PTE_U, PTE_W... all other PDEs are zero The Page Table Page at physical address 0x00002000 (which is PPN 0x00002): PTE 0: PPN=0x00005, PTE_P, PTE_U, PTE_W PTE 1: PPN=0x00006, PTE_P, PTE_U, PTE_W... all other PTEs are zero The Page Table Page at physical address 0x00003000: PTE 0: PPN=0x00005, PTE_P, PTE_U, PTE_W PTE 1: PPN=0x00005, PTE_P, PTE_U, PTE_W... all other PTEs are zero List all virtual addresses that map to physical address 0x00005555

Consider the following 32-bit x86 page table setup. %cr3 holds 0x00001000. The Page Directory Page at physical address 0x00001000: PDE 0: PPN=0x00002, PTE_P, PTE_U, PTE_W PDE 1: PPN=0x00003, PTE_P, PTE_U, PTE_W PDE 2: PPN=0x00002, PTE_P, PTE_U, PTE_W... all other PDEs are zero The Page Table Page at physical address 0x00002000 (which is PPN 0x00002): PTE 0: PPN=0x00005, PTE_P, PTE_U, PTE_W PTE 1: PPN=0x00006, PTE_P, PTE_U, PTE_W... all other PTEs are zero The Page Table Page at physical address 0x00003000: PTE 0: PPN=0x00005, PTE_P, PTE_U, PTE_W PTE 1: PPN=0x00005, PTE_P, PTE_U, PTE_W... all other PTEs are zero List all virtual addresses that map to physical address 0x00005555 Answer: 0x00000555, 0x00400555, 0x00401555, 0x00800555

What's on the stack? Describe layout of a stack and how it changes during function invocation?

Example stack : : 10 [ebp + 16] 5 [ebp + 12] 2 [ebp + 8] RA [ebp + 4] FP [ebp] [ebp - 4] : : : : [ebp - X] (3rd function argument) (2nd argument) (1st argument) (return address) (old ebp value) (1st local variable) (esp - the current stack pointer)

Describe the steps and data structures involved into a user to kernel transition (draw diagrams)

Interrupt path

What segment is specified in the interrupt descriptor? Why?

Interrupt descriptor

Interrupt gate disables interrupts Clears the IF flag in EFLAGS register Trap gate doesn't IF flag is unchanged

Which stack is used for execution of an interrupt handler? How does hardware find it?

Interrupt path

Describe organization of the memory allocator in xv6?

Physical page allocator

Where did free memory came from?

Describe how a per-cpu variables are stored in xv6?

swtch in xv6 doesn t explicitly save and restore all fields of struct context. Why is it okay that swtch doesn t contain any code that saves %eip?

2958 swtch: 2959 movl 4(%esp), %eax 2960 movl 8(%esp), %edx swtch() 2961 2962 # Save old callee save registers 2963 pushl %ebp 2964 pushl %ebx 2965 pushl %esi 2966 pushl %edi 2967 2968 # Switch stacksh 2969 movl %esp, (%eax) 2970 movl %edx, %esp 2971 2972 # Load new callee save registers 2973 popl %edi 2974 popl %esi 2975 popl %ebx 2976 popl %ebp 2977 ret 2093 struct context { 2094 uint edi; 2095 uint esi; 2096 uint ebx; 2097 uint ebp; 2098 uint eip; 2099 };

Stack inside swtch()

Suppose you wanted to change the system call interface in xv6 so that, instead of returning the system call result in EAX, the kernel pushed the result on to the user space stack. Fill in the code below to implement this. For the purposes of this question, you can assume that the user stack pointer points to valid memory.

3374 void 3375 syscall(void) 3376 { 3377 int num; 3378 3379 num = proc >tf >eax; 3380 if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { 3381 3382 proc >tf >eax = syscalls[num](); } else { 3383 cprintf("%d %s: unknown sys call %d\n", 3384 proc >pid, proc >name, num); 3385 proc >tf >eax = 1; 3386 3387 } }

3374 void 3375 syscall(void) 3376 { 3377 int num; 3378 3379 num = proc >tf >eax; 3380 if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { 3381 // proc >tf >eax = syscalls[num](); proc->tf->esp -= 4; *(int*)ptoc->tf->esp = syscalls[num](); 3382 } else { 3383 cprintf("%d %s: unknown sys call %d\n", 3384 proc >pid, proc >name, num); 3385 // proc >tf >eax = 1; proc->tf->esp -= 4; *(int*)ptoc->tf->esp = -1; 3386 3387 } }

Thank you!