The trapvector table is in supervisor space, but TRAP executes in...
I am going through email that stacked up over the weekend when you all
were busy with Programming Lab 4. Since doing Prog 5 means first getting
Prog 4 correct, I wanted to be sure this was clear. If you have no problem
with it, please feel free to delete and move on.
Professor Patt,
I have a question about the implementation of Lab Assignment 4. In the
description, it says:
Protection exceptions occur only when the machine is in user mode,
and a memory location in system space (locations x0000 to x2FFF) is
accessed by the user program.
This implies that an exception occurs for any access, either a read
or a write. But the clarifications say:
TRAP should be able to execute in user mode, i.e. it must be able to
access the trap vector table at x0000 to x01FF without causing a
protection exception.
Which definitely means that some addresses in the supervisor space need
to be read. This seems to contradict the earlier statement that an
exception is raised on any access.
So, does an exception occur for any access from user mode to the
supervisor space, or just writes to the supervisor space?
Thanks,
<<name withheld to protect the student who is concerned there is an
inconsistency>>
Actually, there is no problem, although there is a subtlety. The statement
of the problem states that the TRAP instruction must be able to execute in
user mode. As you know, instructions modify the state of the machine. They
can access memory and I/O (load or store), they can operate on values, and
they change the flow of control. As far as the state of the machine is
concerned, the TRAP instruction loads the PC with the starting address of
the service routine. If the service routine is in user space, there is no
problem. Control goes from one user space address to another user space
address.
The fact that the hardware has to access the trapvector table in supervisor
space in order to find the starting address of the service routine is not a
problem in itself. Note this does not mean the user program can read or
write the locations in the trapvector table. If the user program tried to
load the trapvector into R1, for example, a privilege mode exception would
take place.
But the issue here is not reading or writing the trapvector table entries,
but rather using them to change the flow of control. In order for TRAPs
to be able to do that, we would not test for privilege mode in state #15
in our LC-3b machine.
Incidentally, many machines keep the TRAP routines in supervisor space (so
user mode programs can not modify them). We are considering doing that for
the LC-4b. If we do that, the state machine will have to change the privilege
mode to supervisor before completing the execution of the TRAP instruction
cycle. A good state to do that would be state #30. Perhaps something you
might want to do in your EE 382N project if you are still with me a year
from now!
Good luck with Prog 5.
Yale Patt