http://www.jamesmolloy.co.uk/tutorial_h ... sking.html. But my code differs from the tutorial in that
I defined a stack for the kernel separately instead of using the one provided by grub so that I don't have to move the stack as done in the tutorial.
As per the tutorial, to create a child process I have to create a copy of parent process page directory such that all the entries mapping the kernel
are copied whereas for all other entries the data is copied and new page tables are created and mapped to the child page directory. This is done by comparing the parent process page directory to the kernel directory. Since the parent process is a kernel mode process its page directory is the kernel directory itself
Code: Select all
if (kernel_directory->tables[i] == src->tables[i])
{
// It's in the kernel, so just use the same pointer.
dir->tables[i] = src->tables[i];
dir->tablesPhysical[i] = src->tablesPhysical[i];
}
else
{
// Copy the table.
u32int phys;
dir->tables[i] = clone_table(src->tables[i], &phys);
dir->tablesPhysical[i] = phys | 0x07;
}
Since in my implementation the kernel stack is also mapped into the kernel directory this code will not work as the entries for stack
will also be copied from the parent process page directory instead of creating a new stack for the child.
This is how I defined the stack -
Code: Select all
section .multiboot
MultibootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
section .text
STACKSIZE equ 0x4000 ;16KB
loader:
cmp eax, 0x2BADB002 ; verify booted with grub
jne .bad
mov esp, STACKSIZE + stack
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
.test:
push ebx
call kmain
.bad:
jmp $
section .data
align 4 ; stack should be 4-byte aligned
stack:
TIMES STACKSIZE db 0
Please suggest how to get the stack addresses so that the data can be copied while the rest of the kernel area is just mapped and not copied.
-Thanks
Vaibhav Jain