Friday, November 09, 2007

Memory Layout: just after lguest loading bzImage, initrd and page tables.



svg format link: http://www.box.net/shared/static/tg46zrnjzs.svg

Recently I read the source code of lguest. Above is the memory layout when the sample lguest in kernel_source/Documentation/lguest/.

This diagram describes the memory layout just after the sample allocated the guest memory, loaded bzImage and initrd, and initialized the page directory and page tables.

a sample command line usage:
Documentation/lguest/lguest 64 vmlinux --tunnet=192.168.19.1 --block=rootfile root=/dev/vda

its flow:
1, lguest tool in user space, which is the main role in the phase, allocated a chunk of memory specified as memory parameter in command line with mmap system call. As result, guest_base keeps the base address of the chunk. I think here lguest just uses two types of address, virtual address in host space and "physical" address in guest space. So guest_base is the offset value.
2, lguest loaded bzImage or its elf form in the way of segments.
3, lguest loaded initrd. Before loading, lguest must align pages for the initrd file and adjust the initrd_size.
4, Initialize page directory. First, lguest setup the page directory gains the pgdir which points to pgdir array base. Then initialize every item in page directory.
5, Initialize every item in page table. Every item points to a page.

Thursday, November 08, 2007