Mapping kernel high in memory and creating kernel stack

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
skwee
Member
Member
Posts: 73
Joined: Mon Jan 12, 2009 3:11 am

Mapping kernel high in memory and creating kernel stack

Post 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 :)
TCP/IP: Connecting people...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Mapping kernel high in memory and creating kernel stack

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
skwee
Member
Member
Posts: 73
Joined: Mon Jan 12, 2009 3:11 am

Re: Mapping kernel high in memory and creating kernel stack

Post 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.
TCP/IP: Connecting people...
Post Reply