initial stack mystery.. grub? ld?
Posted: Tue Mar 30, 2010 4:10 pm
hello,
i've been programming my os for a couple weeks now, and as i was trying to figure some things out to try some context switching, i noticed my ESP register for my kernel wasn't where i expected.. it's just under the 64kb mark.
my linker file states the base of the executable is 1mb and i've never had any reason to doubt that number until now. i assumed (you know what they say...) everything was loading from grub relative to that address. i've dumped the memory and found code there, so that's great, but ESP is definitely placed just under 64kb.
the stack is declared in the inital asm code after space has been reserved (and 4kb aligned) and referred to by a label after the reserved space in the bss section.
i feel like ESP should initially be at 1mb+64kb because i linked it at 1mb. i've modified my code to move esp 1mb higher (where my kernel was reserving space for it (because i assumed)), but i feel like i'm not going about things the right way. there's a lot of reserved memory 'down there' and it makes me nervous to just let the stack grow 'down there.'
what don't i understand here? is there a way i can force everything to happen/link at 1mb? or should i keep doing what i'm doing and bump it up 1mb higher than 'normal' after boot?
if you need more info, just let me know.
ps: if this has already been answered on this forum somewhere, please tell me how you found it.
i've been programming my os for a couple weeks now, and as i was trying to figure some things out to try some context switching, i noticed my ESP register for my kernel wasn't where i expected.. it's just under the 64kb mark.
my linker file states the base of the executable is 1mb and i've never had any reason to doubt that number until now. i assumed (you know what they say...) everything was loading from grub relative to that address. i've dumped the memory and found code there, so that's great, but ESP is definitely placed just under 64kb.
the stack is declared in the inital asm code after space has been reserved (and 4kb aligned) and referred to by a label after the reserved space in the bss section.
i feel like ESP should initially be at 1mb+64kb because i linked it at 1mb. i've modified my code to move esp 1mb higher (where my kernel was reserving space for it (because i assumed)), but i feel like i'm not going about things the right way. there's a lot of reserved memory 'down there' and it makes me nervous to just let the stack grow 'down there.'
what don't i understand here? is there a way i can force everything to happen/link at 1mb? or should i keep doing what i'm doing and bump it up 1mb higher than 'normal' after boot?
if you need more info, just let me know.
ps: if this has already been answered on this forum somewhere, please tell me how you found it.