Stack Segment Descriptors in Protected Mode
Posted: Tue Mar 18, 2008 8:27 am
http://www.csee.umbc.edu/~plusquel/310/ ... arch2.html
I've been trying to decipher what it says on that page about stack segment descriptors, so I can use it in my GDT:
I've tried all kinds of values for the BASE and LIMIT addresses, but I just can't get the stack to work without causing a triple-fault.
Here's my current GDT entry for the stack segment:
I want to create the segment so that it takes up the entire 4 GB address space and then set ESP to wherever I want. Also, I would like some help with initializing SS and ESP.
If using the entire address space is not possible (only conceptually, because physically I'll never be able to use that much memory), how do I initialize (what values do I need for) the descriptor entry so that the stack it describes expands from physical address 0x80000 to 0x90000 (so that I get 16384 DWORD-sized stack entries).
I know I could just define a normal data segment and use it as a stack, but that has some protection issues if you set ESP to 0. I don't understand what expand-down segments are and how they are supposed to be used, and that link doesn't help much.
Thanks,
Gabriel
I've been trying to decipher what it says on that page about stack segment descriptors, so I can use it in my GDT:
Code: Select all
* Type=2 or 3: A stack segment is defined analogously to Types 0 and 1.
o However, the interpretation of the limit field is different.
+ In this case, all offsets must be greater than the limit.
+ The upper limit is set to base address + FFFF (with D=0) or base address + FFFFFFFF (with D=1).
o This means the stack segment ends 1 byte below the base address.
o Expanding of the stack segment simply involves decreasing the limit.
Here's my current GDT entry for the stack segment:
Code: Select all
SYS_STACK_SEL = $-gdt
gdt4: dq 00CF96000000FFFFh ; limit 0xFFFFF; base 0; present, ring 0, stack, expand-down, writable; page-granular, 32-bit
If using the entire address space is not possible (only conceptually, because physically I'll never be able to use that much memory), how do I initialize (what values do I need for) the descriptor entry so that the stack it describes expands from physical address 0x80000 to 0x90000 (so that I get 16384 DWORD-sized stack entries).
I know I could just define a normal data segment and use it as a stack, but that has some protection issues if you set ESP to 0. I don't understand what expand-down segments are and how they are supposed to be used, and that link doesn't help much.
Thanks,
Gabriel