Segmentation registers are used.

I am trying to understand how memory management is going low and there are a few questions.

1) The book on assembler from Kip R. Irvine says that in real mode the first three segment registers are loaded with the base addresses of the code, data and stack segment when the program starts. For me this is a bit ambiguous. Are these values ​​set manually or does the collector generate instructions for writing values ​​to registers? If this happens automatically, how does he know what the size of these segments is?

2) I know that Linux uses a flat linear model, i.e. uses segmentation in a very limited way. In addition, according to "Understanding the Linux Kernel" by Daniel P. Beauvais and Marco Cesati, there are four main segments: user data, user code, kernel data, and kernel code in GDT. All four segments are the same size and base address. I do not understand why there is a need for four of them, if they differ only in type and access rights (they all produce the same linear address, right?). Why not use only one of them and write its descriptor in all segment registers?

3) How do operating systems that do not use segmentation divide programs into logical segments? For example, how they distinguish a stack from code without segment descriptors. I read that paging can be used to handle such things, but I don’t understand how to do it.

+5
source share
3 answers

Extension to Benoit's answer to question 3 ...

The separation of programs into logical parts, such as code, persistent data, mutable data, and the stack, is performed by different agents at different points in time.

-, ( ) , . (PE, ELF ..), , , . , , , . ( ), - , - ( , ), - , (, DLL) .

, , , , , . . , , ( ) -. .

- , , . RWX , .

, , . , , 64 , , , , ( ) . , . () , , .

, . 16- DOS- (COM EXE) , , - . COM- 64 , IP = 0x100 SP = 0xFFxx, , . DOS EXE CS: IP SS: SP, , , DOS. , , , ( EXE), PSP ( , ), SS: SP CS: IP. , , 16- DOS .

+3
  • , , , ;-) phyical address = segment register * 0x10 + offset, . 16 , 64 , , , ! * 0x10 1 , , . - , , OS , , ELF. , .

  • - . , , GDT. , CPL ( ). , DPL ( ), CPL, ( , ). , , , ​​ . , , GDT.

  • , , , - . - , . , , ( , ). , , , Intel: Intel® 64 IA-32 3: , 1

+4

All Articles