Assignment 1 Questions - Operating Systems | CS 570, Assignments of Operating Systems

Material Type: Assignment; Professor: Roch; Class: OPERATING SYSTEMS; Subject: Computer Science; University: San Diego State University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-em5
koofers-user-em5 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 570 OPERATING SYSTEMS
M
ARIE ROCH
Assignment 1
Part I must be done individually. Part II may be done with a pair programmer if desired.
As with all assignments in this class, qualitative questions should be answered with
grammatically correct sentences.
Due, Monday, Feb 18th at the beginning of class.
Part I – Questions, 20 points each
1. Describe in your own words the process that occurs when a privileged
instruction is executed in the kernel code of a virtual machine with a type I
hypervisor.
2. You are writing user library code for a new operating system, MejorOS for a
MIPS RISC processor. MIPS chips use the instruction syscall in place of
TRAP, but the functionality is the same as a TRAP instruction. You are to
write subroutine int print_string(char *str) which writes a NULL terminated
string (pointed to by str) to the current output device. If successful, the
subroutine should return 0, otherwise 1. You need not do any error checking,
as this will have been done by higher level library routines such as printf
which call print_string.
The kernel programming interface for MejorOS states that to print a string to
the current output device, the value 0x90 should be loaded into register v0
and the address of the string in register r4. Upon returning from the
exception, register r0 contains the result of the system code (0 if successful, 1
otherwise). In addition to syscall, you will need to use the following
instructions:
immediate load: li destination_register, value which
loads the given value (immediate data) into the specified register.
load word: lw destination_register, address, which loads
the contents of address into destination_register.
store word: sw source_register, address, which saves
source_register to the specified address.
Fortunately, you are using a C/C++ compiler which has an extension for
including assembler instructions. Any block preceded by __asm contains
assembly instructions and if the compiler can translate C/C++ variables into
addresses. As an example, if the variable foo was declared as a word sized
integer, one could write a function void bar(int foo) as follows:
pf3

Partial preview of the text

Download Assignment 1 Questions - Operating Systems | CS 570 and more Assignments Operating Systems in PDF only on Docsity!

CS 570 OPERATING S YSTEMS

MARIE ROCH

Assignment 1

Part I must be done individually. Part II may be done with a pair programmer if desired. As with all assignments in this class, qualitative questions should be answered with grammatically correct sentences.

Due, Monday, Feb 18th^ at the beginning of class.

Part I – Questions, 20 points each

  1. Describe in your own words the process that occurs when a privileged instruction is executed in the kernel code of a virtual machine with a type I hypervisor.
  2. You are writing user library code for a new operating system, MejorOS for a MIPS RISC processor. MIPS chips use the instruction syscall in place of TRAP, but the functionality is the same as a TRAP instruction. You are to write subroutine int print_string(char *str) which writes a NULL terminated string (pointed to by str ) to the current output device. If successful, the subroutine should return 0, otherwise 1. You need not do any error checking, as this will have been done by higher level library routines such as printf which call print_string.

The kernel programming interface for MejorOS states that to print a string to the current output device, the value 0x90 should be loaded into register v and the address of the string in register r4. Upon returning from the exception, register r0 contains the result of the system code (0 if successful, 1 otherwise). In addition to syscall, you will need to use the following instructions:

  • immediate load: li destination_register, value which loads the given value (immediate data) into the specified register.
  • load word: lw destination_register, address, which loads the contents of address into destination_register.
  • store word: sw source_register, address, which saves source_register to the specified address.

Fortunately, you are using a C/C++ compiler which has an extension for including assembler instructions. Any block preceded by __asm contains assembly instructions and if the compiler can translate C/C++ variables into addresses. As an example, if the variable foo was declared as a word sized integer, one could write a function void bar(int foo) as follows:

Roch p. 2

void bar(int foo) { /* assembler comments start

  • with ;; and continue to end of line */ __asm { li r3, foo ;; Store address of foo to r lw r4, foo ;; Store contents of foo to ;; register r } }

While function foo is not particularly useful, your print_string function will be used throughout the world on cable & satellite set top boxes, routers, and other embedded devices, earning you as much fame and fortune as the person who wrote the printf/cout functions that you will be using in Part II.

  1. Explain how a multicore microprocessor with separate caches could have incoherency unless hardware designers take specific preventative steps (you need not describe what steps must be taken).

Part II - UNIX assignment 60 points

This is a small programming assignment designed to give you experience in making system calls, and reading manual pages. This program must execute correctly on systems implementing the POSIX standard (e.g. rohan which runs Solaris UNIX, or any modern linux distribution).

Directories are actually special files that contain information about other files. In this programming assignment, you will get your feet wet with system calls and manual pages. In this assignment, you will write your own version of the "ls" command which lists files in a directory. Your version of ls, myls will be significantly simpler than the standard ls. Basic functionality when user executes myls:

  1. If no command line arguments are given, the current directory is listed with white space (use any combination of space, tab, and newline that you wish) between each file. A newline character is written after the last file. By default, any file starting whose first character is “.” will not be listed unless the hidden flag is set (see below).
  2. An optional flag, -h (for hidden), may be specified which will list all files or directories including those that start with a “.”.
  3. One or more command line arguments may be given. Each argument is a directory to list, i.e. "myls a02 a03" should list the files in directories a02 and a03. If any of the specified files cannot be accessed, the error "Cannot access a02" should be printed.