Page 1 of 1

Data Segment problems

Posted: Fri Jun 01, 2007 7:42 am
by slasher
Hi,
I've just changed my data segments from EXPAND UP segments to EXPAND DOWN segments.

The expand up sements were using a base of 0 and limit of 0xFFFFF (32 bits, page granular).

The expand down segments use a base of 0 and a limit of 0.(32 bits, page granular).
(I made this change so that the stack segment will grow downwards.)

When I try to access address 0 or (0x78) which are both in the Interrupt vector table (for real mode), I get a general protection fault.

When I change the expand down segment to use a base of 0 and a limit of 0xFFFFF, the pc just keeps rebooting.

My question is, using a flat model, should my data segment selector be EXPAND UP and the stack selector EXPAND DOWN?

How are you all using this EXPAND UP/DOWN selectors?

(NOTE: When i use EXPAND UP for both DS and SS, I can access those addresses.MY CS selector has a base of 0 and limit of 0xFFFFF and is NON-Conforming.)

Re: Data Segment problems

Posted: Fri Jun 01, 2007 8:20 am
by Brendan
Hi,

For expand down segments, the CPU allows accessed between LIMIT and 0xFFFFFFFF, and generates a GPF for all accesses below the limit. The idea being that you can decrease the limit to make the segment larger without making a mess of current offsets.
slasher wrote:The expand up sements were using a base of 0 and limit of 0xFFFFF (32 bits, page granular).
In this case you'll be able to access zero bytes (from limit + 1 to 0xFFFFFFFF, or from 0xFFFFFFFF + 1 to 0xFFFFFFFF).

If you want to be able to access 4 GB with expand down segments you'd need "LIMIT = 0x00000000".
slasher wrote:My question is, using a flat model, should my data segment selector be EXPAND UP and the stack selector EXPAND DOWN?
Most OSs use the same expand up descriptor for DS, ES and SS. Using an expand down segment for the stack is good in theory (for preventing the stack from overflowing and trashing other data), but it tends to suck a bit once you've got multi-threading and need one segment descriptor per thread.

Mostly, if you're using paging then expand down segments aren't worth the hassle...


Cheers,

Brendan