Regarding enable paging code and swapper_pg_dir.

James Light jlight at srcit.stevens.edu
Sat Apr 2 12:25:35 EDT 2011


On Sat, Apr 02, 2011 at 01:33:21PM +0530, mindentropy wrote:
> On Saturday 02 Apr 2011 2:49:21 am you wrote:
> > On Sat, Apr 02, 2011 at 01:37:12AM +0530, mindentropy wrote:
> > > Hi All,
> > > 
> > >   In the code
> > >   http://lxr.linux.no/#linux+v2.6.12/arch/i386/kernel/head.S#L186
> > > 
> > > I am not able to understand what's the reason for subtracting
> > > swapper_pg_dir with __PAGE_OFFSET(0xc0000000). i.e. movl
> > > $swapper_pg_dir-__PAGE_OFFSET Shouldn't it be movl $swapper_pg_dir,
> > > %eax?
> > > 
> > > Thanks.
> > > 
> > > _______________________________________________
> > > Kernelnewbies mailing list
> > 
> > I'm no expert here, but I think the reason that it is coded that way has to
> > do with the fact that the swapper_pg_dir is defined to be the value that
> > will be used once the CPU has switched to Protected Mode, but this asm
> > code in head.S is executing while the processes is in Real Mode.
> > 
> > The instruction that enables paging and protected mode addressing is on
> > line 190, I believe.
> > 
> >      -James
> 
> Yes but why the subtraction with __PAGE_OFFSET? 

To put the physical address into cr3 later.
$swapper_pg_dir is not the PHYSICAL address of the PGD.
So they have to subtract 0xc0000000 (kernel code segment base linear address)
from that the get the physical address as the logical address can not be used
yet because the paging unit isn't enabled yet.

Again, my understanding may be wrong. As I said before, I'm just learning this
as well.
     -James



More information about the Kernelnewbies mailing list