On 04/13/2011 01:23 AM, Philip Pemberton wrote: > Hi guys, > > There's been some on-list chatter regarding adding an MMU to the > LatticeMico32 core. I've been scribbling down some ideas regarding this, > and figured it'd be nice to share :) > > My first thought was "how do we handle supervisor mode?" -- nearly every > MMU I've seen has some separation of user and kernel code. The x86 has > Rings 0 to 3, the ARM has User, Supervisor, IRQ and FastIRQ modes (and > OS Mode if you tie an ARM1 to a MEMC1), and so on. > > So what we need is a way to differentiate between at least two privilege > levels, and a way to allow Supervisor code to switch to User mode, but > not the other way around. > > There's a fairly obvious solution to this: > > - We have two bits of privilege store, giving four privilege levels. > > - We have two PRIVILEGE registers (2x2bits = one nibble). These are > called "Last Privilege" and "Current Privilege". In my opinion one bit is enough. Kernel mode or user mode. Any other setting is unlikely to be used.
> > - Current Privilege is immutable. Last Privilege is mutable, but only > to the extent that its current value can be reduced. That is to say, you > change it from L3 (Supervisor) to L2, L1 or L0 (User), but only the CPU > can set it back to L3. > > - On reset, both Current Priv and Last Priv are set to L3 (Supervisor) > > - When an Exception is invoked (SYSCALL, IRQ, NMI, or one of the Abort > exceptions), the CPU copies Current Privilege into Last Privilege, at > the same time that it copies IE into EIE. > > - When an ERET is executed, Last Priv is copied into Current Priv. > This restores the privilege state of the code which was running before > the exception occurred. We assume that an exception cannot occur while > another That is a bad assumption. For example: Interrupt during syscall or debug break during interrupt and even interrupt nesting can cause an exception while another is already running. But that shouldn't cause any problems even with your current design. For example the current linux kernel for lm32 tracks already whether we are in user or kernel mode in software. Whenever an exception occurs the current mode is saved in the exceptions stackframe and the mode is set to kernel mode. When returning from the exception the mode is restored to it's previous setting. This makes it possible to nest exceptions. - Lars _______________________________________________ http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org IRC: #milkymist@Freenode Twitter: www.twitter.com/milkymistvj Ideas? http://milkymist.uservoice.com
