Page 1 of 1

Segmentation concept Help!!!

Posted: Tue Sep 14, 2010 7:22 am
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?

Re: Segmentation concept Help!!!

Posted: Tue Sep 14, 2010 7:30 am
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

Re: Segmentation concept Help!!!

Posted: Tue Sep 14, 2010 10:51 pm
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...

Re: Segmentation concept Help!!!

Posted: Wed Sep 15, 2010 12:02 am
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 ?

Re: Segmentation concept Help!!!

Posted: Wed Sep 15, 2010 12:20 am
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?

Re: Segmentation concept Help!!!

Posted: Thu Sep 16, 2010 5:33 am
by tushs
I got ans its Identity mapping concept ... Thank's for help!!!

Re: Segmentation concept Help!!!

Posted: Fri Sep 17, 2010 3:43 pm
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.