Open books, handouts, notes. Write on these pages where appropriate. Points: 1 (40), 2 (20), 3 (20), 4 (20)
1. Short answer.
a. What 32-bit x86 CPU register is saved by both call (the ordinary function-call instruction) and int $n (the older system-call instruction)? Which 32-bit register is saved by int $n but not call?
b. Suppose two devices send in interrupt signals at the same moment. But the x86 CPU sees only one at a time. What device makes this happen? What action in the interrupt handler enables the second interrupt to be sent to the CPU?
c. For x86 Linux, where in memory is the clock tick interrupt vector, i.e., where in what table?
d. In x86 Linux, how does execution get to function system_call?
e. Suppose the CPU is running at user level, and then, a few CPU cycles later, in kernel mode. List the two most commonly occuring mechanisms that cause this transition.
f. In which of the following UNIX/Linux execution environments are interrupts always allowed, sometimes allowed, never allowed: circle the right answer
--running at user-level: always/sometimes/never
--running at kernel-level: always/sometimes/never
a. Suppose a Xinu semaphore was created with count 1 but now has count -2. What can you say about the number of processes waiting for this semaphore?
1. Suppose you need a fast way to receive a byte from either of two COM ports, whichever gets an input byte first. Devise and implement this in a function that accepts two base ports (usually 0x2f8 and 0x3f8, but leave it general), and returns the first byte that arrives at either port, and the base port of the port that received the byte. Clearly at least one return value has to be delivered via a pointer argument. Write it with inpt() calls directly to the hardware, using polling. Use the back of a page or an additional page.
CS644 Midterm Exam, pg. 2 of 3
2. Consider the following UNIX program. Note that getpid() is a system call that returns the process pid.
#include
<stdio.h>
int x =
2;
int
main()
{
int z = 4;
x = 3;
if (fork()) {
x++;
z++;
}
printf(“%d: %d %d %d\n”, getpid(), x , *y,
z);
}
a. Here are some abbreviations for various data areas in memory:
UC user code, including library user code
UD user data, including library user data
Consider the process image just before the fork. Where (
x
z
main
write system call instruction executed by printf
exit system call instruction
b. Just after the fork is executed, how many copies of x are there? Of z?
c. Given parent pid of 3000 and child pid of 3002, what is printed out? If more than one output is possible, show it or discuss. For simplicity, assume each individual printf string comes out intact.
CS644 Midterm Exam, pg. 3 of 3
3. Consider the solution to hw2, using UNIX/Linux POSIX semaphores, running in test1 after the forks with 2 worker processes.
a. List the system calls in use.
b. Here is a picture of the VA space layout of the parent:
Being careful to align areas of memory if appropriate, make parallel drawings of the VA spaces of the two workers:
c. Add in a representation of the shared memory in use, and show the location of the struct locker that holds the pointer to the shared memory in each process. Draw an arrow from the struct locker to the shared memory to show the pointer.