Page 1 of 1

Mapping kernel high in memory and creating kernel stack

Posted: Wed Feb 11, 2009 1:40 pm
by skwee
Hi there, how are you?
I finally finished my PMM and VMM.
Now I mapped everything from 0x1000 to 0xEndOfKernel (+placement address) (I reserved block 0 (first 4K of memory) to be able to return NULL if allocation failed and get page fault if try to access to 0x0).
I'm one step before starting the kernel heap, but I heard a lot about Higher Half Kernel, like Mapping the kernel not 1:1 but somewhere around 0xC... I was wonder how I can achieve this? One solution I tough about is mapping 0x100000 till end of kernel, to the pages I want (Lets say 0xC0000000) and than manually adjust eip, but something tells me it wont work.
So I would like to know how its done?

Also one more question, now I use 4KB stack defined in krnldr.asm file:

Code: Select all

STACKSIZE	equ	0x4000						; 4KB stack
... Some more code, especially .text  section.
...........
mov		esp,	stack + STACKSIZE
......... more code that pushes multiboot info and call kernel
section .bss
align	32
stack:
	resb	STACKSIZE
However I know (I think >.<) That stack suppose to be at the end of kernel space and grow towards the kernel heap while heap should expand towards the kernel stack.
How I can remap the stack (Do I need it?!)?

Thanks a lot :)

Re: Mapping kernel high in memory and creating kernel stack

Posted: Wed Feb 11, 2009 3:08 pm
by Combuster
Think about whether you really need > 4KB of stack space. If you still want to relocate the stack, just make sure there are no references to anything on the stack, copy the stack, adjust the EBPs on the stack, load the new ESP, and you should be set.

Re: Mapping kernel high in memory and creating kernel stack

Posted: Wed Feb 11, 2009 4:02 pm
by skwee
Hey, thanks for the answer :)
I dunno if I need more than 4KB for stack, my kernel is not going to do some deep recursion, or nested calls. Anyway the reason I want to move the stack, is as I said so the stack will grow towards the heap, now stack is growing towards the kernel (actually now when I think if I place the heap straight after kernel I still get the desired result: 0x0..not my stuff...0x100000..kernel.....heap--->......<---stack).
Well anyway thanks for the answer :)

About higher half, sorry I forgot that wiki have explanation for that.