Reputation: 1941
__USER_CS,__KERNEL_CS,__USER_DS,__KERNEL_DS, all have base=0x00000000 and limit=0xfffff. What I can't understand is that these linear addresses will give identical physical addresses (I think I might be wrong here). The linear address (thus the physical address) generated will be same in all cases which means that user and kernel structures are stored at the same place. Also, explain to me how, contrary to all this, we say that kernel structures are stored at the upper 1 GB and user structures are stored at the lower 3 GB.
Kindly point out my mistakes in the understanding of paging and segmentation. Thank you.
Upvotes: 1
Views: 520
Reputation: 127467
You are mistaken in assuming that the linear address map to physical addresses in a 1:1 fashion. What happens instead is that page tables are used to map linear addresses to physical addresses. Each process has a different set of page tables, providing address separation and virtual memory. In the kernel space, the page tables of the first 3GB point to "virtual" addresses; the last GB maps in a roughly 1:1-fashion to physical addresses (in some configurations). Protection of kernel-mode pages is achieved by (not) setting the USER access bit in the page table entry.
Upvotes: 2
Reputation: 47602
Which platform are you talking about? For x86 they are all different (from arch/x86/include/asm/segment.h
) :
#define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
#define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
#define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
#define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
and
#define GDT_ENTRY_DEFAULT_USER_CS 14
#define GDT_ENTRY_DEFAULT_USER_DS 15
#define GDT_ENTRY_KERNEL_BASE 12
#define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
#define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
Upvotes: 0