Вы находитесь на странице: 1из 9

HOMEWORK #2 SPRING 2015

2.3 Device interrupt vector address are called programmable if they can be
changed after the hardware has been purchased from the vendor. Why are
programmable vector addresses needed?
Device interrupts can be programmable (re-vectored) to a Non-BIOS ISR by a user program. The
process of re-vectoring is to first disable processor interrupt using CLI (PC assembly language
instruction sets flags[9:9]=0) and then execute the mov instruction like shown below.
Mov: Device Interrupt vector location (i.e., segment:offset address of User ISR)
Why programmable vector needed?
The main reason of having a programmable vector is because BIOS ISR does not provide
complete operation of user needed function. For example, keyboard keystrokes to reach user
space.
For example, the process of kbd keystrokes to reach user space using kgetc and kputc methods.

2.5 Find out why and how disks are formatted into sectors.

2.8 Find out what the keyword register means in C.


In C, compilers usually use register key word for initializing a variable to optimize the access
of the variable. It is used for accessing the memory faster than the normal initialization, so the
variables which are most frequently used in a C program can be put in registers
using register keyword. The keyword register hints to compiler that a given variable can be put
in a register. Its compilers choice to put it in a register or not.
Example: register int i; ()

2.9 Write a C program using only kgetc and kputc (together with the loer-level
kbdgetc and witty procedures) which will read a character from the keyboard
and echo it to the screen. Do not use any other components of PC-Xinu.
Analyze what happens when you enter special characters such as Tab, Back
Space, Return, Ctrl-U and PC function key F1.
#include <conf.h>

#include <kernel.h>
#include <tty.h>
#include <kbdio.h>
Xmain() {
Int d;
kputc(d,kgetc(d));
}

Int kgetc(d)
Int d;
{
Int ch;
While ( (ch=kbdgetc() == NOCH) )
;
Return ( (ch==RETURN) ? NEWLINE : ch);
}
Void kputc(d,ch)
Int d;
Char ch;
{
If ( ch==RETURN || ch==NEWLINE) {
Ch = NEWLINE;
wtty(RETURN);
}
Wtty(ch);
}

Additional Exercises:
1. Explain how the address space works in PC Xinu. Give an example.
Answer: The PC Xinu process addresses up to 1024K bytes of memory because physical
addresses are 20 bits long. The 20-bit physical address is an unsigned number because
instruction set cannot handle 20-bit addresses instead it uses logical address specified by two
unsigned 16-bit numbers, one called a segment:offset address.
The 20-bit physical address and segment:offset address are expressed in hexadecimal
notation.

Segment:offset
To translate the segment:offset address into a 20-bit physical address (5 hexadecimal digits),
segment component should be multiplied by 16, which is equivalent to appending a loworder zero.
Ex: 14CF*16 == 14CF0
Here, 14CFO is the 5 hexadecimal digits & 14CF is segment component
Example: The segment:offset address is

2. Provide a detail explanation of figure 2.2. Explain the purpose of the


each of the sections displayed in the figure
Answer:

The above figure shows the usage of the Main memory in PC Xinu. The address space from
00000 to FFFFF (which comes to 1MB) is divided into three sections, which in each has its own
usage. The memory from 00000 to 003FF is allocated for Interrupt Vectors. Second section
memory starts from 00400 to 9FFFF and allocated for User memory. The third section memory
starts from A0000 through FFFFF and is allocated for Graphics and ROM BIOS.
To mention, all address refers to only one physical address space; there is no memory
management hardware on the basic PC.
Detail explanation of each Section:
Section 1: This particular address space is used to handle device interrupts. To mention,
each device has a unique vector interruption. Apart from device interrupts, it also handles
exceptional conditions, which in real time program exceptions like division by zero. Also,
hardware errors
Section 2: This address space is allocated for user programs. Also, programs like DOS,
PC Xinu, which is equivalent to 8000 lines of code will use this particular space.
Section 3: The basic input/output system (BIOS) has been allocated into this particular
address space BIOS = Basic input/output system provides a virtual I/O machine. To mention,
PC Xinu runs on top of DOS, which is uniprocessing system. So, only one program runs at a
time. Also, BIOS provides user-accessible routines for accessing KBD, VID, DSK transfer
operations and those routines are not re-entrant

3. Draw the FLAGS word register, see figure 2.4, and provide at least 5 of
the interrupt bits.
Answer:
Flag register:

15

14

13

12

11
OF

10

9
IF

7
SF

PF Priority Flag (1 even, 0 odd)


ZF Zero flag (1- zero, 0- non-zero)
SF Sign Flag (1- negative, 0- positive)
IF Interrupt Flag (1-enable, 0- disable)
OF Over-flow flag (1- overflow, 0- No overflow)

6
ZF

1
PF

4. Explain in detail how Vectored Interrupts works. See section 2.3.4


Answer:

Vectored interrupts:
The vectored interrupts takes place in when an external device needs to communicate
with the processor. External devices system like clock etc communicates through
interrupts. Also, CPU checks for interrupts at the end of the each instruction cycle. The
below Interrupt handling algorithm runs repeatedly checking each instruction.

Interrupt handling algorithm:

Start

Fetch next
intruct

Execute
instruct

Interrupt
enabled?

Check for
interrupt
&
call interrupt

HALT

HALT

Step 1: If the processor is running with interrupts enabled, it checks the interrupt line after
executing each instruction to see whether an interrupt needs processing.
Step 2: Processor
-

For handling the interrupt from the device, the processor disables further interrupts
and sends an acknowledgment over the bus, requesting a return type from the
interrupting device. It is of one byte quantity.

Step 3: Device
-

The device with a pending receives the acknowledgement and responds by returning
its interrupt type V to process on the data bus.

Step 4: Processor
-

When it receives the interrupt type, the processor pushes the current FLAGS word
and the CS:IP address on the stack, loads the CS:IP address from the two words in
memory starting at location 4V, and continues executing instructions beginning at the
new location.

Step 5: CPU jumps to appropriate interrupt service routine (ISR) to process interrupt.

5. Explain in detail how the Exceptional Conditions work. See section 2.3.5
Answer: Exceptional conditions and interrupts are handled similarly.
Steps:
1. If there is any exception, the processor first pushes the current FLAGS register and CS:IP
address into a stack
2. Loads new CS:IP from a vector location in memory
Example of Exceptional Conditions:
Division by zero, memory error or a power failure.

6. a. Provide an explanation of software interrupts.


Answer: Software interrupts are program-invoked instructions like subroutine calls, but
are handled by the 8088 processor just like hardware interrupts. The form of an interrupt
instruction is INT n (n is an interrupt type).

b. Why software interrupts are important.


Answer: Software interrupt mechanisms are often employed by operating systems to
permit user access to system services without the user needing to know the address of the
service subroutine. It allows the ISR code to be modified or relocated without having to
make changes in user code.

7. Draw figure 2.12 and provide a detail explanation of the storage layout
for a C program.
Answer:

Code

Data

Stack

heap

Text segment: It forms the lower part of address space and is referenced using CS
segment register. It consists of code for the main program and all the procedures.
includes code for the main program and all procedure, occupies the lower part of the
address space and is referenced using the CS segmenet register.
Data segment: It occupies the higher region of the address space and it can be referenced
using DS segment register. It contains program data followed by stack and heap.
which contains program data followed by the stack and heap, occupies the higher region of
the address space. Data segment references are made using the DS segment register.
The SS (Stack) segment: this SS register always points to the same segment as the DS
register. The stack occupies a fixed-size component of the data segment address space
immediately beyond the program data.
The Heap: The area between the stack and the top of the data segment address space is
free space which may be used for runtime storage allocation.

8. Draw figure 2.13 and explain why there is three STACKS in this C
layout.
Answer:
Code

Data

Stack#1

Stack#2

Stack#3

Free space

When PC Xinu runs multiple processes, it allocates a stack area for each of them. These
stacks generally allocated from the bottom of free space. Thus, if three processes start,
their stacks are allocated contagiously upward. Because the hardware does not protect
one user from another, stack overflow in one process will, unfortunately, destroy the data
in a stack that belongs to another process. Stack space is returned to the free list
whenever a process exits. PC-Xinu also provides a system call that allocates free spce to
user processes for general use.

Вам также может понравиться