Hurry Up! Get 15% Please upload the order before 30th April, 2019. T&C applied Order now !

# Operating Systems

CS370: Operating Systems Final Exam Winter 2018

Name:

The theme of this exam is that you are to write a new OS based on a simplistic OS I wrote for a senior project, lo these many years ago. Your hardware platform is a single board computer with a 6809 processor, an RS-232 serial interface for a terminal, and an SD card for storage. Details will appear as needed in the questions, but if anything seems to be missing, feel free to ask.

1. (4 points)        If the maximum speed of our RS-232 port is 115,200 bits/sec, how many characters per second can we transmit to the terminal?                                 Ans. Speed of RS 232 port is 115200 bits/sec.                          ........

The theme of this exam is that you are to write a new OS based on a simplistic OS I wrote for a senior project, lo these many years ago. Your hardware platform is a single board computer with a 6809 processor, an RS-232 serial interface for a terminal, and an SD card for storage. Details will appear as needed in the questions, but if anything seems to be missing, feel free to ask.

1. (4 points)        If the maximum speed of our RS-232 port is 115,200 bits/sec, how many characters per second can we transmit to the terminal?                                 Ans. Speed of RS 232 port is 115200 bits/sec.                                                            8 bits=1 character                                                                                                     115200 bits= 1/8*115200                                                                                                               =14400 characters                                                                                 Therefore we can transmit 14400 characters per second to the terminal.

b.(4 points) If the CPU averages 1µS per instruction, how many instructions can we have in the transmit interrupt handler and still be able to transmit at full speed?                      Ans.

1. Write the byte to the port.

2. Burn 1 μS in a tight loop.

3. Turn on the strobe signal.

4. Wait another μS.

5. Turn off the strobe signal.

6. Wait another μS.

parport write data(port , byte );

udelay (1);

parport write control (port , ctl | PARPORT_CONTROL_STROBE);

udelay (1);

parport write control (port , ctl );

udelay (1);

1. count ++;
2. (4 points)    What is the difference between access control lists and capabilities?

 Access Control List (ACL) Capability List An access control list (ACL) can be defined as a table that states what access rights each user has, in a computer operating system, on a particular system object, which may be individual file or a file directory A capability can be termed as a token, a key or a ticket that provides a permission to the possessor to access an object or an entity inside a computer system. Each object identifies its access control list and has a security attribute. The list has an entry for each system user with access privileges, including the privilege to read a file, to write to the file, and to execute the file. A capability has a set of privileges or rights. We can store that subject's capabilities with each subject we With ACLs it is assumed that the authentication was unforgettable. We need a way to make capabilities unforgettable with capabilities, A good fit in the system where more user centric action is required Not a good fit in the system where more user centric action is required

1. (4 points) What are the different roles of the upper half and the lower half of a device driver?                                                                                                            Ans.  The upper half routines are called by the device-independent I/O routines such as the read and the write. They do not work on the device directly. They enqueue requests for transfer instead and depend on the routines in the lower-half, in order to perform transfers later. The drivers use interrupt-driven processing to avoid the drawbacks of polling.                                                         The lower-half routines are termed as the interrupt routines which are called by the input and output interrupt dispatchers.

The lower and upper half routines exchange data by writing to and reading from the two circular buffers: the input and output buffers. These buffers are required because the communication between an SLU device and the CPU is asynchronous. The input buffer holds characters received from the terminal by the input interrupt routine, but which are not read by any upper-half routine. The output buffer contains data which is written by a upper-half routine but which is not transferred by the output interrupt routine.

1. (4 points) Which of the classes of systems in the DOD Orange Book represents the highest level of trust?                                                                                                   Ans. The Division A class represents the highest level of trust in the DOD Orange Book. It has Verified Protection. And formal methods are used to guarantee that all the subjects and the objects are controlled with the required discretionary and mandatory access controls. The design, as well as the development, implementation, and documentation are taken care of in a formal and detailed way.

2) The 6809 processor works with 16-bit memory addresses and is byte addressed (i.e. 8-bit data units). The physical memory on the computer is 128KB. Further, the upper 16KB of the virtual address space is divided into an 8KB section for I/O and an 8KB section for boot ROM.

1. (3 points) If the two 8KB blocks at the upper end of the virtual address space are the only reserved parts of the address space, how much does that leave for RAM?                Ans. The physical space left for RAM would be=128-2*8(Address space)-8(I/O)-8(Boot ROM)= 96kB
2. (3 points) The system has a very simple memory management unit that works with a small number of relatively large pages. If the RAM portion of the memory space is divided into three pages, how large is each page?                                                              Ans. Three pages is 2^16 bit=8192 bytes. So one page would be 2.7 Kbytes.
3. (3 points)       How many page frames can the physical memory be divided into?     Ans.  The physical memory can be divided into 3 page frames.
4. (3 points)       How many bits are needed then to specify the page frame number?    Ans. Page frame size would be 32 kbytes, i.e , 2^8 bit. Therefore 8 bits are needed to specify the page frame number.
5. (4 points) If the OS takes one physical page that is shared in the virtual space of all processes and each process is given two full pages of RAM, how many processes can be resident in memory at once?                                                                                       Ans.
6. (4 points) Sketch the virtual and physical memory spaces showing which regions are used for what purposes.

3) As is typical, the 6809 keeps interrupts disabled between the time that an interrupt is received and the time that a return from interrupt instruction is executed. Input and output to the terminal is interrupt-driven. In particular, each time a character is received from the terminal, an interrupt gets generated, and each time a character is finished being transmitted to the terminal, an interrupt is generated. You have two registers for reading and writing characters. Access to them is provided by routines called inserial() and outserial().

1. (5 points) If there is a buffer of characters that have been received and not processed and another buffer of characters that have been generated but not transmitted, briefly describe the operation of the receive interrupt handler.

An interrupt handler or interrupt service routine (ISR) is a function that the kernel executes in response to a specific interrupt.

Each device that creates interrupts have an associated interrupt handler.  The interrupt handler for a device, is part of the device's driver (the kernel code that manages the device).

We have an interrupt controller (IRC) on the mainboard, which acts as a multiplexer between the devices and can raise an interrupt and the CPU:

Every device is associated with an IRQ (the number on the left). After every execution the CPU senses the interrupt-request line. If a signal is detected a state save will be performed and the CPU loads an Interrupt Handler Routine which can be found in the Interrupt Vector which is located on a fixed address in memory.                                 3b. As a mutex can be released only by the thread that acquired it, the OS will normally release all the mutexes the thread holds when it terminates, either normally or due to exception. The OS cannot do it for binary semaphores as the OS does not know who is supposed to increase its value back to 1. When designing and coding a great care must be taken to ensure semaphores are not lost, especially if an exception occurs. With a mutex, often it is not needed to take care of exceptions and let the OS do the cleanup. (i.e. in case the thread does not modify the shared data but uses a mutex to make sure it reads a coherent state of a complex data structure)Algorithms & Programming  Home

1. (5 points) What type of mutual exclusion mechanism should be used in the upper half of the driver when putting characters into the transmit buffer?

As a mutex can be released only by the thread that acquired it, the OS will normally release all the mutexes the thread holds when it terminates, either normally or due to exception. The OS cannot do it for binary semaphores as the OS does not know who is supposed to increase its value back to 1. When designing and coding a great care must be taken to ensure semaphores are not lost, especially if an exception occurs. With a mutex, often it is not needed to take care of exceptions and let the OS do the cleanup. (i.e. in case the thread does not modify the shared data but uses a mutex to make sure it reads a coherent state of a complex data structure)

1. (5 points) Using a mixture of pseudo-code and C, draft out the transmit routine in the upper half of the driver with the lock and unlock operations in the right places.

For communicating with the SD card, there’s a different type of serial communication that’s used. You have three signals: a clock, a one bit input, and a one bit output. These are available to you on the low order three bits of an I/O port called A. You have routines to access that port called ina() and outa(). The technique you need to use is called bitbanging. For each bit you send, you will need to set the bit value on the output, set the clock to 1, and finally set the clock to 0. You should transmit the bits least significant bit first.

(5 points) Using a mixture of pseudo-code and C, draft a routine that takes a byte (character) 1. Project Outline

A program is required to simulate a game of 'memory' or 'concentration' as commonly played by children. The playing board consists of cards face down. Each card appears twice in the set placed randomly on the playing board. The player clicks on two cards turning them over to reveal their faces. If a match is made, the faces remain visible. If there is no match, the cards are turned over again.

As the player makes attempts to find matches, the program counts and displays the number of matches that have been made as well as the number of attempts that have been taken.

2. Solution Specification

2.1 Structured Design Chart

This application will use three modules:

choose() - receives data about the cards which the user has clicked, tracks if each click is a first or second pick of each turn and displays the correct face image for each card.

check() - checks for matches, then counts the number of attempts and, further matches and turns the cards back over, if no match is made.

shuffle() - shuffles the cards at the beginning of a new game.

The program will use two click events, one for the cards and one for the 'Shuffle Cards' link. The diagram below shows the relationship between the modules:

?

2.2 User Interface

The UI for the initial version of this game is quite simple. It consists of a table with 3 rows and 2 columns. Each cell contains a card with the back showing to simulate the card laying face down. Beneath the table is a link that will call the shuffle() function and a count of the number of attempts made.

A possible UI is shown below:

?

2.3 Pseudocode

The algorithm for each of the three main functions in this program are shown below. Preceding them are a set of global variables that will be required:

/* Global Variables */ picks = 0 //counts how many picks have been made in each turn first choice //stores index of first card selected second choice //stores index of second card selected matches = 0 //counts number of matches made numAttempts = 0 //counts the number of attempts made back card = "blank.png" //shows the back of the card when turned over   var faces = [] //an array to store the images for the front of the cards

The 'choose' Function

choose(card) //'card' is the index of the selected card passed from HTML IF 2 picks made THEN do nothing //stop player choosing 3 cards ENDIF   IF picks is 0 THEN store card index in firstchoice variable show image corresponding to first card clicked set picks = 1 ELSE set picks = 2 store card index in secondchoice variable show image corresponding to second card clicked Run timer to call check() in 1 second ENDIF END

The 'check' Function

check() stop timer increment numAttempts by 1 display the number of attempts IF secondchoice = firstchoice THEN add 1 to matches set picks to 0 IF all matches found THEN show alert declaring game over and how many attempts were taken reload the game ENDIF ELSE turn over first card to show back turn over second card to show back set picks = 0 ENDIF END

The 'shuffle' Function

shuffle() /* Set variables */ temp //temp variable used for swapping swaps //counter for number of swaps made i //random number j //random number   FOR swaps = 1 to 10 i = choose random index from array j = choose random index from array Move card[i] to temp Move card[j] to card[i] Move temp to card[j] END END

4) You are relieved to learn that although SD cards usually have FAT file systems on them, you will be implementing a somewhat more simplistic file system. Here, the disk (SD card) will be divided into a number of contiguous groups of blocks, each of which will contain all the files in a particular directory. The first block of each of these directory areas is the directory listing itself. The first four bytes of the directory block are an integer giving the number of blocks in that directory area. After the block count, the remainder of the directory block is an array of entries, each of which contains the file name, the starting block number of the file, and the number of blocks in the file. For subdirectories, the starting block number in the directory entry is the block number of the directory block for the subdirectory. The second block of each directory area is a list of the free blocks in that area.

1.
 List of free blocks
 directory
 Directory listing
 ….
 4
 3
 2
 1

(5 points) Translate this verbal description of the disk organization into diagrams that illustrates how data is laid out on the disk.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         4 bytes-no. of                                                                                                           blocks             in that directory area                                                                                                                  block number of the file                          file         (for sub directory, it is block number of sub directory)                                              number of blocks in the file

1. (5 points)    How can we tell if a given name in a directory refers to a regular file or a subdirectory?                                                                                                               Ans. After the four digits of the first block of the directory entry, the next digits determine whether it is the block number of a  regular file or a sub directory.
2. (5 points) This type of structure has some pretty significant limitations. List at least five limitations on the use of files and directories in this system that are not present in the Inferno kfs file system we discussed in class.                                                                           Ans.         Note that there are limitations on how the floppy image can be used. You cannot use itto build a bootable USB memory device. If you do try to boot Inferno from such a device,

pbs will be loaded by the BIOS, and pbs will load 9load, because it also uses the BIOS.

However, 9load does not use the BIOS to load the kernel image, and 9load does not include

support for USB storage devices. Likewise, 9load also generally fails on USB-connected

d)(5 points) Using a mixture of pseudo-code and C, draft a routine that will create a file in this file system structure.                                                                                             Ans.

5) (20 points) Although never completed in the original system, there was always the intention of supporting multiple processes. However, in the particular hardware before you, there is no clock to generate periodic interrupts. Of course, this implies that your multi-processing will have to be cooperative rather than pre-emptive. Based on the descriptions above, discuss how you would approach the scheduling and context switching when supporting multiple processes here. Be sure to include not only what the OS does but also how user processes interact with that functionality.                                                          Ans. The Operating system will have to follow a scheduling and context switching approach to handle multiple processes. A round robin algorithm would be a good option for this system. A fixed time could be set for each process. If the process is not completed in the time -slot, the process details can be saved in the stack and context switching can take place.  Thus, it reduces the waiting time for the processes on an average and multiple processes get executed.

Each of the user process would wait in a queue to get executed. When the process gets ready for execution, it executes for the given time slot. It finishes execution if the execution time is less than the time slot provided else the process details get saved to the stack for later execution and the process gets added to the queue. The procedure gets repeated till the process completes its execution.

Thus, the processes cooperate with each other and also the resources get utilised without creating a deadlock.