Question
-
Compare
kern/mpentry.S
side by side withboot/boot.S
. Bearing in mind thatkern/mpentry.S
is compiled and linked to run aboveKERNBASE
just like everything else in the kernel, what is the purpose of macroMPBOOTPHYS
? Why is it necessary inkern/mpentry.S
but not inboot/boot.S
? In other words, what could go wrong if it were omitted inkern/mpentry.S
? Hint: recall the differences between the link address and the load address that we have discussed in Lab 1.#define MPBOOTPHYS(s) ((s) - mpentry_start + MPENTRY_PADDR)
Before running,
mpentry.S
will be move toMPENTRY_PADDR
. However the link address ofmpentry.S
is based onKERNBASE
, so we need macroMPBOOTPHYS
map link address to new address start fromMPENTRY_PADDR
. -
It seems that using the big kernel lock guarantees that only one CPU can run the kernel code at a time. Why do we still need separate kernel stacks for each CPU? Describe a scenario in which using a shared kernel stack will go wrong, even with the protection of the big kernel lock.
Separate kernel stacks keep each CPU's function calls consist. If using a shared kernel stack one CPU's function call may return to another CPU's function call. This makes executing flow messed up.
-
In your implementation of
env_run()
you should have calledlcr3()
. Before and after the call tolcr3()
, your code makes references (at least it should) to the variablee
, the argument toenv_run
. Upon loading the%cr3
register, the addressing context used by the MMU is instantly changed. But a virtual address (namelye
) has meaning relative to a given address context--the address context specifies the physical address to which the virtual address maps. Why can the pointere
be dereferenced both before and after the addressing switch?Because in both
mem_init()
andenv_setup_vm()
theenvs
is mapped to array read-only by the user at linear addressUENVS
. Thee
is mapped to same physical address in both address context. -
Whenever the kernel switches from one environment to another, it must ensure the old environment's registers are saved so they can be restored properly later. Why? Where does this happen?
To restore environments we need the information about registers like
esp
andeip
. It was done at_alltraps
intrapentry.S
.