What is the true difference between a real mode program and a protected mode program?
Asked Answered
U

3

12

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?

Urbani answered 27/10, 2013 at 14:54 Comment(1)
Have a look here [Real Mode VS Protected Mode][1] [1]: geek.com/chips/…Extension
U
13

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.

Urbani answered 28/10, 2013 at 9:16 Comment(0)
B
9

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.

Burkhard answered 27/10, 2013 at 15:6 Comment(0)
D
9

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.

Dannettedanni answered 28/10, 2013 at 10:6 Comment(1)
I doubt if an object code in real mode would contain the actual physical addresses. it only contains the offsets which are appended to the CS value once it is shifted 4 bits to the left.Urbani

© 2022 - 2024 — McMap. All rights reserved.