ECE291 Protected FAQ, Version .4284945543A

Q: Is there ECE291 sample source code?

YES get it from here!. This was made with NASM and WDOSX. It requires that you have MS's nmake program (or you altenatively, you can modify the Makefile into a batch file if you want.) It also comes with the binaries for NASM and WDOSX... you can also view the NASM and WDOSX pages yourself.

Q: What is protected mode, and why would I want to use it?

Protected mode is a mode available on the x86 of which the most important feature is the way memory is handled. The MPs we have programmed this semster have all been in a mode called real mode. In real mode, you had to address memory with a segment and offset. (Think Lecture 2) One of the problems with this system is that you are limited in the size of your segments. Although, this was not a huge issue in our MPs, it becomes a huge issue with more complex data structures. For example, if you were interested in doing 16 bit graphics, at 800x600, it would take 800x600x2bytes of memory just to hold a screen. Obviously this would not fit in one segment(I believe the limit is 65535 bytes) So what do you do? Well one solution would be to split it up into many different segments.... but, first, that would become very difficult and complex to program, and second, real mode limits the number of segments you can have (I believe its under 10). And due to Mr Bill/ionaire/ Gates, you are pretty much stuck in a world that lives under the 1 meg mark. In fact, Dos itself lives only in this sub-os terrain. So, what about these phat new 64 megabytes main memory machines???? Well another solution you have are stuff like EMS and XMS, expanded and extended memory systems, respectively. These, with the aid of drivers, allow you to page memory in and out of your main memory. But, wouldn't it be cooler to leave the constraints of segments and offsets behind? Protected mode aka flat mode, allows you to address all of memory as if it was a huge sequential array. What I mean is, you could theoretically address from 0 to 2^32-1 bytes of memory, simply using a 32 bit value/register. This totally simplifies programming tasks, because you no longer are confined to small segments, and allow to just flow out your code as your heart desires. This is the advantage of protected mode.

Q: Sounds great! Where can I find some introductory reading materials....

If you own the Brey textbook (was required in prior semsters, but was optional this semster), Brey mentions some protected mode in the latter chapters ( I believe 13 or 14). A good primer is available at http://www.x86.org/articles/pmbasics/ . In fact, www.x86.org is a very useful site if you want the lowdown on the x86 processor...

Q: Can I use MASM? and can I use CodeView? What about alternatives? Can I mix C code?

The quick answer, is Yes you can use MASM. But, I am not sure if you can use CodeView to debug protected mode based programs... It is probably best to state this here, if you choose to go ahead and use protected mode or do something else outside the norm 291 project, you are probably traveling in uncharted terrority. Mainly, most of the 291 staff are not really experienced in this realm, and can thus only guide and perhaps point you in the right direction, but, please do not let this stop you from doing what you want in your project. We encourage you to be unique and ambitious, just make sure you are prepared to handle the completion of your project. That said, there are many VALUABLE resources available to you at your fingers tips..... the Internet. Returning to the original question, yes you can use MASM. However, there is a snag. MASM's linker will not generate the appropiate header to put you into protected mode, but, instead only provides facilities to make real mode binaries. You can still use MASM assemble your code, however, you will need to find another program that will STUB the code to put you in protected mode. In fact, most likely, you'll want a stub program(or rather, a dos extender) that will not only put you into protected mode (in which case you will be outside of DOS), but provide you with the basic DOS type interrupt functions you would have had if you were just in real mode. If you ever played any early 1990 game, such as Duke Nukem, you are probably aware of the DOS/4GW 32-bit DOS extender that loads you up. This perhaps the most popular one employed in almost every 90s DOS game before the existance of DirectX. As far as I know, DOS/4GW 32-bit DOS extender comes with the Watcom complier/assembler which is a commercial software piece. (Although, it is not that expensive). This entire package can be an alternative to MASM, or, you could possibly look into getting MASM and DOS/4GW 32-bit DOS extender to work together. You might also want to look at Borland's products, they make compliers and assemblers, and they might have a Dos extender as well. If you saw my project from last semster, Hell, you might notice that we did not use DOS/4GW. But there is another, free, choice. NASM (netwide assembler) as an assembler and WDOS32X as an dos extender. Both of these software were freely available off the net In fact, it is possible to use this dos extender with MASM if you desire. (You'll need to get it to assemble into 32 bit "MZ" or PE w/o Win32 API first... see wDOSx homepage) As for C, you'll have to look at trying to link to an object files, which is possible as well. On the debugger front, most of these extenders or assemblers come with debuggers that are capable of debugging protected mode files.

Q: Is protected mode hard?

No. Just read up on the DPMI standard and learn how the selectors and descriptor table works and you'll be fine.

Q: Is there a better FAQ? This one sucks!!!

Yup - look at this one!.

Q: Other resources:

Tenberry's commercial dos extender - This is the extender included with Watcom, and is also avaiable for purchase as seperate product

DPMI 1.0 specs - This specification is extremely handy when trying to make dos callbacks to reach items such as video cards, sound cards, cdroms, etc. Note most dos extenders only support a subset of the .9 specs, and very few of the 1.0 specs.

32 Bit Programming Homepage - This is perhaps one of the most useful pages on protected mode programming. Many useful links plus software that can make your life easy.

And of course, there are many search engines out there that will turn up tons after tons of pages related to protected mode programming.