Segmentation concept Help!!!

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
tushs
Member
Member
Posts: 28
Joined: Mon Aug 02, 2010 7:43 am

Segmentation concept Help!!!

Post by tushs »

Hi, I read lots of pages, linux book about description of x86 segmentation, I got pretty good info but I have few doubts please help me on this. let m explain what I understood,
Segmentation is used to keep text, data, stack part separated so that we can manage access to respective memory. In linux the four segment user code, user data, kernel code kernel data has base offset as 0x00 and limit is 4 GB, user space has about 3 GB and kernel space has about 1 GB address space. kernel space begins somewhere 0xc000....
To access kernel data or code I need to load proper cs, ds same is true for user code and data. GDT is array of segment descriptor which has information of these limits and all.
My Que is: according to above segment arrangement any address above 3 GB is valid in user mode since base address of segment is zero and limit is 4 GB. so how segmentation separates user mode and kernel mode or raise exception on invalid access? how code and data are separated? what i mean by this is say 0x0010 is valid code address and data address for code and data segment but what will be its actual physical address because there can be same physical address for certain segment:offset pair?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Segmentation concept Help!!!

Post by Brendan »

Hi,
tushs wrote:My Que is: according to above segment arrangement any address above 3 GB is valid in user mode since base address of segment is zero and limit is 4 GB. so how segmentation separates user mode and kernel mode or raise exception on invalid access? how code and data are separated? what i mean by this is say 0x0010 is valid code address and data address for code and data segment but what will be its actual physical address because there can be same physical address for certain segment:offset pair?
In this case, segmentation is not really used at all. Paging is used to separate user-space from kernel-space (and potentially to separate code from data too).


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.
tushs
Member
Member
Posts: 28
Joined: Mon Aug 02, 2010 7:43 am

Re: Segmentation concept Help!!!

Post by tushs »

Ok, Most of web pages or doc talk about the virtual and physical address for first 8 MB or so are same i.e physical address is same as virtual address and all this space is used by OS to keep its data structures and DMA buffers. I am not getting calculations because of which this virtual and physical address are same, please give example if anybody knows...
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Segmentation concept Help!!!

Post by gerryg400 »

tushs wrote:Ok, Most of web pages or doc talk about the virtual and physical address for first 8 MB or so are same i.e physical address is same as virtual address and all this space is used by OS to keep its data structures and DMA buffers. I am not getting calculations because of which this virtual and physical address are same, please give example if anybody knows...
This type of stuff is very OS specific so generally not true. On x86 most kernels are higher half. Although in Linux, the first 8MB of RAM is (or used to be) mapped to both 0x00000000 and 0xc0000000 during the boot process. Is that what you are talking about ?
If a trainstation is where trains stop, what is a workstation ?
tushs
Member
Member
Posts: 28
Joined: Mon Aug 02, 2010 7:43 am

Re: Segmentation concept Help!!!

Post by tushs »

assume that we had some data structure initialized in real mode now we need to shift to 32 bit protected mode if paging is not enabled new 32 address and actual physical address will same i.e my pointer to data struct is valid, Now when paging is enabled value of pointer will (or might) be invalid since its corresponding physical address will be different. And to avoid this we need same virtual physical address mapping..
please correct me if I am wrong. what I want to know is,
Although in Linux, the first 8MB of RAM is (or used to be) mapped to both 0x00000000 and 0xc0000000 during the boot process.
how this mapping happens?
tushs
Member
Member
Posts: 28
Joined: Mon Aug 02, 2010 7:43 am

Re: Segmentation concept Help!!!

Post by tushs »

I got ans its Identity mapping concept ... Thank's for help!!!
rdos
Member
Member
Posts: 3286
Joined: Wed Oct 01, 2008 1:55 pm

Re: Segmentation concept Help!!!

Post by rdos »

I use 00100000 as a base and E0000000 as a limit for the usermode code and data selector for flat applications. There is no sense in giving applications access to kernel-space, or v86 reserved areas.
Post Reply