Question

I have been developing an 32 bit OS and just implemented a ELF loader. I can load executable however I would like running programs to each have there own data segment. Now from what I have gathered from research in 32 bit protected mode the data segment refers to a 64k block right? So lets say I set DS to 16, and had code like mov dword eax,[test]. The processor gets the what is at test like (DS * 0xFFFF) + test right? So if test was 0 then the actual address it would be reading at would be 983025 or 0xEFFF1? Is this right or am I totally off

Était-ce utile?

La solution

Now that you are developing your own OS, the data segment, as well as code segment and stack segment can be almost whatever you like.

In 386 PE segment registers "point" to a descriptor table, residing in physical memory, where each segment is assigned 8 bytes (or possibly 16 bytes in x64?) to define the base address, read/write/execute flags and the segment size.

Typically these limits are set as 0 and 2^32(-1), which is also called a flat mode.

Even when using linux/cygwin etc. compliant gcc, it's quite possible to benefit from the segmented architecture knowing that each memory access uses a default segment depending on the base register. As long as all local variables are accessed using mov [ebp + ... ] or mov [esp + ...] as base register, Stack Segment is used. This can be used in exception handling to distinguish in between stack corruption vs. heap corruption. It can be utilized in automatically growing data / stack segments etc. It can be used in providing separated data areas for applications -- perhaps one could implement memory mapped file API through segmentation -- as opposed to linux, where fs: and gs: are reserved for kernel.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top