Data Segment problems

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
slasher
Posts: 17
Joined: Sun Oct 24, 2004 11:00 pm
Contact:

Data Segment problems

Post 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.)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Data Segment problems

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply