What is R6?
A student writes:
Dear Dr. Patt,
I have been trying to get started on Programming Assignment 4. I have a
doubt regarding User Stack Pointer (USP) and Supervisor stack pointer
(SSP). In appendix A, it has been mentioned that R6 contains the value
of USP in user mode and the value of SSP in supervisor mode. I am
little confused about this since R6 is a general purpose register and
we have
been using it in our assembly programs. Since it contains the value of
USP during user mode (if i am not wrong it is the mode in which our
assembly code runs), how can we use it during assembly coding.
Won't it change the
value of R6 and we will not be able to access the USP ?
Thanks
<<name withheld to protect the student who could be seeing double>>
R6 is one of the 8 registers accessible to the program that is running.
Some programs are written by users that will run without privilege, and
some programs are written by programmers (such as o/s programmers) that
will run as part of the operating system.
We could in fact have two sets of registers, one for unprivileged code
and one for privileged code. Indeed, some ISAs (or microarchitectures,
at least do).
On a context switch, we save all the registers anyway.
Since R6 is usually used as the stack pointer, some ISAs take the position
that for security purposes it is really better (and it is) to have separate
stacks for user code and privileged code. It is not absolutely necessary,
but it can prevent some sloppy coding providing security holes.
I decided to adopt this approach for the LC-3b. Ergo, two stack pointers,
USP and SSP. When user code is running (privilege bit = 1), R6 means USP.
When system code is running (privilege bit =0), R6 means SSP. Your job:
when you are moving from one privilege mode to the other, it is important
to save the value of R6 from the old mode and load R6 with the value from
the new mode.
Does that help? If not, please ask the TAs or me.
Yale Patt