Disclaimer: I'm probably missing something here, but in my books that i've read i cannot find an answer...
Anyways,
I am getting into making a simple memory manager for my kernel, all the goodies of a keyboard interrupt driver and printf are done. I write out my kernel's memmory usage like this:
0x0001 0000 = Start of stack (mov esp, 0x00010000 right before main of c kernel is called)
0x0010 0000 = Kernel load address
0x0040 0000 = The start of my little malloc function.
all my malloc() does is return the address of a pointer (which initally points to memory at 0x00400000) and increases the pointer based on the size requested. It's dirt simple and there just so i could make some linked lists...
Now, I want to set the top of the stack to the the address right below where my kernel code starts, to 0x000FFFFF. When I do this, Bochs gives me a panic.
I want to do this to use that memory sitting between the stack and the kernel code. Grub will not allow me to load a kernel below 1 meg.
Is there some rule that says the stack must start as 0x0001000?
If so, where could I find more information on this and/or why does this have to be this way?
Some information would be appreciated. Don't be afraid to tell me I'm missing something extremly simple that I should have picked.
Thanks,
Simrook.
Location of stack
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Location of stack
i suggest you get some tutorial on PC address mapping before you go on : the memory range between 0x000A0000 and 0x000FFFFF is used by video memory and BIOS ROM ... so you're unlikely to set up a stack overthere sucessfully.
Now just let's thing about it a bit more, you're stack is starting at 0x10000 (that is, 64K) and can safely expands to somewhere about 0x8000 (32K -- some memory before this is used by BIOS variable and by your bootsector you might not wish to overwrite) ... which still means 32KB left for your system stack ... This is pretty huge ! unless you plan to allocate tons of bytes on your kernel stack (which i don't recommend), it should be sufficient to get the kernel booting ...
Remember that kernel stack cannot be "virtualized" like a user stack would be: requesting 1MB for a kernel stack implies that MB to be locked forever (or virtually forever)...
Now just let's thing about it a bit more, you're stack is starting at 0x10000 (that is, 64K) and can safely expands to somewhere about 0x8000 (32K -- some memory before this is used by BIOS variable and by your bootsector you might not wish to overwrite) ... which still means 32KB left for your system stack ... This is pretty huge ! unless you plan to allocate tons of bytes on your kernel stack (which i don't recommend), it should be sufficient to get the kernel booting ...
Remember that kernel stack cannot be "virtualized" like a user stack would be: requesting 1MB for a kernel stack implies that MB to be locked forever (or virtually forever)...