Pergunta

I know the difference between a real mode and protected mode from the OS and hardware perspective.

But I am trying to figure out What does a program 'knows' about real mode or protected mode? how can you say while looking at an source code/object code that it is a real mode program or not?

Looking for an answer, All I could come up with is that a 'real mode' program uses BIOS subroutines along with OS subroutines whereas a 'protected mode' program uses only OS subroutines. instruction code differs since opcodes for registers are different and offset addresses are of different length. Is there any other feature that differentiates a real and protected mode program?

Foi útil?

Solução

a 'real mode' program uses BIOS subroutines along with OS subroutines whereas a 'protected mode' program uses only OS subroutines.

instruction code differs since opcodes for registers are different and offset addresses are of different length.

Outras dicas

The main difference is the mode the cpu is in. In protected mode the OS can use features like paging and virtual memory. Also real mode code is never in 32 bits whereas protected mode code can be 16 bits or 32 bits. Every x86 cpu starts in real mode and the OS must switch to protected mode.

how can you say while looking at an source code/object code that it is a real mode program or not?

If there is a direct mapping(one-to-one) between the physical and virtual memory, the program is executing in real mode. To be more precise, since Virtual Memory is not activated in real mode, the program executes in 16 bit mode, where every address "viewed" by the source code/ object code, is the actual physical address on RAM.

The protected mode, on the other hand, has virtual memory feature enabled. Hence the mapping between the address accessed by the source code/object code is different than the actual memory location accessed in RAM.

To detect this, you can just check whether the paging flag is enabled or disabled in the CPU when the source/object code is executing.

For x86 based CPU, you can check the value in CR0 Register. if the CR0 Register is empty, the program is running in real mode.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top