Computing.Net > Forums > Programming > protected mode/real mode question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

protected mode/real mode question

Reply to Message Icon

Name: kelly
Date: July 12, 2002 at 21:08:42 Pacific
Comment:

I have a goal of building an OS from scratch that combines linux and windows. Anyway apart from my chalenges that lay ahead of me, my question is how do I switch between PM and RM when programing in assembly? I am learning assembly programing for the Intell 80X86 and pentium family of microprocessors.



Sponsored Link
Ads by Google

Response Number 1
Name: borelli33
Date: July 12, 2002 at 21:28:19 Pacific
Reply:

To start with, that can be a fairly daunting task if you don't already have YEARS of practice in assembly, however, not being afraid of something difficult is one of the things that breeds greatness (just ask Linus Tuvald. Anyways, PM/RM is not so much a software issue. The OS controlling the processor requests that the processor switches between one mode to the other and as such it is a hardware condition specific to the CPU. The problem their is that the processor will swich to protected mode from real mode but to do the reverse it insists on restarting the computer. Originally this was designed to prevent protected memory problems (addressing differences between the two modes) but is not necessary with the advent of the Pentium (although Intel has chosen to preserve this scheme). Anyways, I would study intently on the Intel CPU design and function where as it is imperative to learn in order to use either of these two memory conventions successfully.

Good luck!

borelli33@netzero.net


0

Response Number 2
Name: Jim
Date: July 12, 2002 at 23:13:13 Pacific
Reply:

Let me quote what is says in chapter 22 of the i486 manual about this:

The only way to leave real-address mode is to switch to protected mode. The processor enters protected mode when a MOV to CR0 instriction sets the PE (protextion enable) bit in the CR0 register. (For compatibility with the 80286 processor, the LMSW instruction also may be used to set the PE bit.) See Chapter 10 "Initialization: for other aspects of switching to protected mode.

The processor re-enters real-address mode if software clears the PE bit in the CR0 register mith a MOV CR0 instruction (for compatability with the 80286 processor, the LMSW instruction can set the PE bit, but cannot clear it). A procedure which re-enables real-address mode shoud proceed as follows:

Chapter 10 discusses the things you have to do before you can actually switch to protected mode without messing something up. Mostly you have to set up your GDT, LDT, and IDT. There is also a list of things you need to do before you switch back to real mode. However, restarting the hardware is no longer necessary on processors 80386 and up. I have written a couple of programs that switch to protected mode and back, and it's not too hard. However, I recommend you find some sample source code. Linux switches to protected mode. That's the hard part, and that source code is freely available.


0

Response Number 3
Name: kelly
Date: July 13, 2002 at 11:54:13 Pacific
Reply:

thank you both, that is a big help, perhaps I should consider useing some of the freely avalable linux code, Though I want to design and build completly from scratch maybe useing a few open source modules would be benifitial to me if I am to succed. I have found a far amount of web sites that focus on teaching OS development, and all of the site I have found so far, the author has yet to suced in completing his/her own OS and are simply shareing what they have learned and some of their own code they deveoped. But it indeed will be a daunting tast, and day by day I am realizeing more and more how much of a task this truely is. However I will not give up, I will continue my mission, as imposible spells "I'm possible" and thus I must not give up hope. I will learn a lot about computers day by day, and I look forward to the day when I can boot my computer and be presented with the gift of life, a child I will call mesch.

10X so much to everyone for all your help.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


plz help c++ graphics



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: protected mode/real mode question

Protected Mode And 32-bit Real Mode www.computing.net/answers/programming/protected-mode-and-32bit-real-mode/10917.html

Real mode int's in protected mode? www.computing.net/answers/programming/real-mode-ints-in-protected-mode/10875.html

switch from real to protected mode www.computing.net/answers/programming/switch-from-real-to-protected-mode/11705.html