expand-down 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
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

expand-down stack

Post by sancho1980 »

hi

the intel "system programmer's guide" has got the following to say:

"If the size of a stack segment needs to be changed dynamically, the stack segment can be
an expand-down data segment (expansion-direction flag set). Here, dynamically changing the
segment limit causes stack space to be added to the bottom of the stack."

Does anybody know how I have to read this? The base address of the stack egment sure is the address of the low end of the stack space. So suppose I were to change the limit dinamically, does that mean the stack base (and with it the stack pointer) is automatically adjusted?
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Re: expand-down stack

Post by urxae »

sancho1980 wrote:hi

the intel "system programmer's guide" has got the following to say:

"If the size of a stack segment needs to be changed dynamically, the stack segment can be
an expand-down data segment (expansion-direction flag set). Here, dynamically changing the
segment limit causes stack space to be added to the bottom of the stack."

Does anybody know how I have to read this? The base address of the stack egment sure is the address of the low end of the stack space.
Actually, that's the trick. With normal segments limit controls what the highest valid address in the segment is, but with the expansion-direction flag set it determines the lower valid address. The base address becomes the upper limit of the physical memory you can access through the segment instead of the lower limit.
This means that lowering the limit will increase the space in an expand-down segment, adding extra addressable memory to the bottom of the segment.
(This is all IIRC from a slightly obscure section of the processor manual that I've never used myself, so you might want to reread the relevant part of the manual with this information in mind instead of assuming it's all entirely correct :).)
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

urxae wrote:The base address becomes the upper limit of the physical memory
Actually, segment bases and limits refer to virtual memory if paging is enabled.

@sancho1980: I recommend you use flat segmentation and paging if you like to be portable as the 64 bit machines don't like segmentation that much. You can easily protect a stack with non-present pages either side of it.

Regards,
John.
urxae
Member
Member
Posts: 149
Joined: Sun Jul 30, 2006 8:16 am
Location: The Netherlands

Post by urxae »

jnc100 wrote:
urxae wrote:The base address becomes the upper limit of the physical memory
Actually, segment bases and limits refer to virtual memory if paging is enabled.
Argh, I know that. I have no idea why I made that mistake :oops:.
(Maybe I haven't yet caught up on enough sleep since the ICFP contest)
Post Reply