News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Confused! about Real and Protected modes

Started by AeroASM, March 12, 2005, 02:58:27 PM

Previous topic - Next topic

AeroASM

I need to deal with three things: Real and Protected modes, 16 and 32 bit code, and the Segmented and Incremental linkers.

I have a program that starts in real mode but needs to end up running 32 bit code.

1. Is it true that only 16 bit code can run in real mode, and 32 bit code can only run in protected mode?

2. Can I use the Segmented Executable linker to link 32 bit code?

3. In 32 bit mode, can I still call BIOS interrupts?

Mark_Larson

Quote
1. Is it true that only 16 bit code can run in real mode, and 32 bit code can only run in protected mode?

no.  You can have a 16-bit protected mode code segment.

Quote
3. In 32 bit mode, can I still call BIOS interrupts?

only if their is a 32-bit protected mode version of the interrupt.  For most there aren't 32-bit protected mode versions.  You can read ralf brown's list to find out which ones you can use.  IF you  have ever used DOS4G/W, when it puts you in protected mode, it will make the processor go into real mode to execute BIOS interrupts.  And then it will go back to protetected mode to continue executing your code.
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

AeroASM

alright then,

2. Can I use the Microsoft Segmented Executable Linker to make 32 bit code?

4. Can I run 32 bit code in real mode?

Gustav


> 4. Can I run 32 bit code in real mode?

It depends on what you mean with 32bit code. You can use 32bit registers in real-mode, but using 32bit offsets usually isnt possibly (with some tricks and limitations it is, though, and then it is called "unreal" mode).

MichaelW

Quote2. Can I use the Microsoft Segmented Executable Linker to make 32 bit code?

Yes.

Quote4. Can I run 32 bit code in real mode?

If by 32 bit code you mean 32-bit protected mode code, no. You cannot run protected-mode code in real mode or real-mode code in protected mode, but a program can contain both protected-mode and real-mode code, and the program can switch from one mode to the other.

Some of Agner Fog's test programs start out in 16-bit real mode, optionally switch to 32-bit protected mode and then return to 16-bit real mode.

http://www.agner.org/assem/

eschew obfuscation

hutch--

Aero,

The distinction between REAL and PROTECTED mode has its basis in the history of computer hardware. Early DOS OS versions worked in REAL mode which meant that the running program wrote directly to memory that it had access to and while this has some simplicity advantages, it also allowed you to overwrite operating system memory so it was garranteed to crash once this happened.

I remember doing things like this when working with direct video memory above the real mode address B800 where CGA colour text mode worked. Mess up a loop and it kept writing well after the end of CGA memory and with a video routine, you could see it trashing the whole DOS upper memory area just before it overwrote the BIOS data and crashed.

Protected mode memory is controlled by a memory manager so it is slightly slower but it has the advantage that if an application tries to read or write to memory that it did not allocate, the memory managment shuts it down and tells you why.

The old windows 3.? series OS versions had rudimentary protected mode but because of the type of multitasking, it could be bypassed with an errant application that messed everything else up as well. 32 bit Windows became a lot more robust as the memory management placed each app in its own memory space and better enforced memory errors. These are normally called exceptions and what happens when you have an app that crashes is that the exception was not handled by the app so the OS default exception handler closed it down.

Simplicity and access go for REAL mode but reliability and consistency go for protected mode.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

OK, thanks everyone so far, but just two more questions:

5. How do I switch between real and protected modes?

6. In real mode I do stuff by writing to memory and outputting to ports; how do I do anything in protected mode?

pbrennick

AeroASM,
Why on earth are you not googling this stuff!  It is everywhere!  Sometimes I wonder...

http://my.execpc.com/~geezer/os/pm.htm

is a nice tutorial that I 'googled'

Robert Collins also posted a very complete discription that you can google using 'enter protected mode'

Do some of this stuff yourself!!!!!!!!!!!!

Paul

AeroASM