Figure 1 - Running other Operating Systems in your current OS with a PC Emulator.

Introduction

I think that one of the most important ways of being a real professional programmer is to design and build an Operating System. It is not enough to read how an OS works, you have to build one with your own hands.

Now, I would list what you will gain from learning how to develop an Operating System:

A programmer is like an astronaut in space, the more he knows about the spaceship he is flying, and how to fix it in case of a problem, it is more likely that he would return safely back to earth. In the case of a programmer, the more he knows about the PC and the Operating system, his programs would be more reliable, stronger, and faster, and with less bugs.

Learning the executables file format (helps a lot).

Learning the Assembler (Every one would admit, that knowing assembler is a wonderful thing).

Many guest operating systems can be run using the emulator, including DOS, several versions of Windows, BSDs, and Linux. Bochs can run on many host operating systems, including Windows, Linux, Mac OS X and the Xbox.

Bochs is mostly used for operating system development (when an emulated operating system crashes, it does not crash the host operating system, so the emulated OS can be debugged) and to run other guest operating systems inside already running host operating systems. Some people use it to run old computer games inside their non-compatible computers.

Create a file name bochsrc.txt (this file is the initialization file for the emulator) and enter in this string: floppya: image="MyOS.img", status=inserted. You can replace the file name MyOS.img with any file name you want (it must be the file that bximage.exe created (or any file of the right size)).

Now, you need some kind of binaries to replace the image (you can take the BOOT.bin file from my first article and replace it in the first 512 bytes of the image you created.

Now, run bochs.exe, and it would open two windows: <!--?xml:namespace prefix = st1 /-->a console window (for debugging) and a GUI window (this window simulates a screen of the emulated OS).

You can run your image with bochsdbg.exe for debugging.

You can create floppies' images, hard disk images, and CD-ROM (*.iso) images, and replace on them any Operating System you want (like WinXP etc.) and debug them.

A more advanced look at Bochs

Figure 4 – a typical mother-board.

All this you can build with Bochs by only writing a simple configuration to a text file. This is why Bochs is so wonderful:

You can configure and build a whole PC, all you need to do is write the PC configuration to some text file (for example, bochsrc.txt) and place it in the Bochs folder. Here is an example of an advanced configuration file:

set reg = expr (change a CPU register to the value of an expression) - for example, set esi = 2*eax+ebx.

For more information, check the documentation that comes with Bochs.

Conclusion

Now I am sure you feel like a PC engineer working for some mother-board company. This configuration is a very wonderful thing, because you can build any kind of PC you want, and test your OS on it.

Another very good thing in Bochs is that it comes with source code, so it is like having all the hardware specification from the OS developer point of view. Also, it can help a lot for debugging your OS, because from the source code, you can know exactly what is wrong.

This is a list of Terms that may be new for you:

ATA (the protocol for reading and writing to hard disks).

ATAPI (the protocol for reading and writing to CD-ROMs).

CMOS (a RAM chip on your mother board that is powered by a battery, this RAM saves all your PC settings that you see when entering the BIOS setup (what shows up when you press the Delete key when you start you computer) - this is really called CMOS setup).

GDB (a debugger for debugging other Operating Systems from a different computer).

PCI (Peripheral Component Interconnect - this is a standard that describes how to connect the peripheral components of a system together in a structured and controlled way).

Points of Interest

You can get the source code of Bochs (also for compiling with MSVC 6). I needed to do some hacking to get Bochs to compile with MSVC 6 and MSVS 2005. If you have compiled it, how did it compile for you? And what happened if you changed some of the #define identifier values, for example, #define BX_DEBUGGER 1 (in Config.h): did you successfully compile it?

Another good PC emulator (but it can't debug the OS) is Microsoft PC Emulator (you can download it from the Microsoft web site).

If you have any questions or you need help, feel comfortable to send me an e-mail. If you have a subject or a point you want me to write about, please note it in the forums (this would help a lot for future articles).

Here you can download the new source code to my Boot sector program from my first article.

These are the fixes I made in the BOOT Sector:

When it finishes reading a track, it switches to the other side.

I added the BIOS Parameter Block to make the diskette (or the hard disk) a valid FAT diskette.

When resetting the drive with INT 13h, move the drive number to the register DL.

I would continue writing if I see this article interests people.

The next in this series of articles that I would write would go in to the details of developing your own OS, for example, details like OS design, programming the file system, EXE format, setting up for Protected mode, switching to Protected mode, handling interrupts, programming the PIC, writing an ATA/ATAPI driver, writing a floppy driver, DMA, using BIOS32 (a special BIOS interface for Protected mode), writing your kernel with MSVC, driver for graphics display, stage 1 and 2 of loading the OS etc.

These are the tools you would need:

A good Hex editor (I am using Hex workshop (but it is not free)). I'm sure you would find a free Hex editor very easily in the Internet.

MASM (v7-v8) (it is very easy to find a site that you can download it from).

Presentation is very good, orientation is focused and the direct instruction based on practical experience helping the reader develop a tool chain says a great deal about the quality of this discussion.

Additionally, while we are debating hex editors - it is most likely an issue of user preference based on how they work and organize their data. Another such tool is HxD a freeware hex editor with all of the basics covered and then some as the commercial developer oriented tools may be a stretch/overkill for some and other free editors might not appeal.

Regardless the general suggestions are a starting point for the tools by title where the real message is that you need a tool specifically to fill a a development space for a nice comprehensive workflow and this excellent data delivered by S. Keller.

Mybe consider using this emulator if you'r running on PPC Sparc, and others but using this eulator on an x86 machines makes no sense.
There are more transparent emulators that use the physical CPU instead a virtual one.

Hello, I am a software developer hobbyist. Right now, I lack experience in complex subjects of programming such as OS development. I'm getting really good at VB.net and C#.net. This lack of experience may be because of my age, especially since I'm only 14. I was reading both articles, but on this one, I can't seem to get the thing to work. In the first article, you talk about what a boot sector was and you had an example. I got to work by using your Utility, and I did see the "Loading OS..." prompt on the system boot. The problem is on this article. You say to "Run - bximage.exe", I did that. Then you say to set it to these settings:
bochsrc.txt - File Name // What is this supposed to do?
1.44 mb - Size // I understand this.
floppya: image="MyOS.img", status=inserted - String // I don't know where to put this string, and when I open up my bochsrc.txt it is blank, but it has invisible text in it.
boch.exe - Debugger // When I Enter "6", it tells me nothing to boot or something like that after it finishes reading bochsrc.txt.
BOOT.bin - BootSector // You say, "Now, you need some kind of binaries to replace the image (you can take the BOOT.bin file from my first article and replace it in the first 512 bytes of the image you created." What do you mean by this?
Could you please explain to me what I'm supposed to do in order to get it working, and as a starter for me get it to work with your samples. I'm very interested in learning how to Develope Operating Systems, and I think that my knowledge in software development, mixed with hopefully knowledge in making OS's would be an excellent field for me in the future.
Also, could you point me towards some new or recent books on OS Development, Programming, Debugging, and Publishing. I don't know if they sell these areas together or seperate, so I mentioned them all.

Most of my learning on OS dev was from experience and articles I found on the internet, but I also read some books that helped me a lot, must of them were old books, that I found in some university library.

And about bochsrc.txt there are help files that would tell you exactly what to set.

If you need any more help you can e-mail me and I would be happy to help you.

Okay, thanks.
Yea, I know anybody who sets out to learn something new in programming must read alot, because in my 8th grade year, I learned Python language, and then, after knowing the fundamentals of programming, I learned VB.net by reading hundreds of articles from the basics up. On April 28th, after developing version 1 of my Advanced text/code/word processor, I entered in a TSA (Technology Student Association) State level competion and I won. Since then, I have been adding more to my application, and have recently started teaching myself c#.net and c++.net by reading alot of the examples here on codeproject. I also picked up assembler language which I believe is also referred to as binary code right? I don't want to mix up two different things. Anyways, yea the basics of binary code I learned, but I'm am still unfortunately ten miles away from the level you're at in OS developement, I'll keep practicing like you said.
Thanks for replying so soon, I see that some of these messages, while answered, weren't answered right away. Some of them were like 6 months. lol.
Regards,
vbcoder7331

yaar there is proble with me when wrote the boot sector to my disk dive, it was full and my os shows zero space free, zero space used about that disk drive. when the utility asked for file that which file you want to converd in boot sector i gave a text file with extension .txt which was contains some text in it.

i have Win xp sp2
now plz tell me about this problem
i m student of software engineering
plz..... help me

Well I guess Windows XP doesn't let users messing up and writing boot sectors as they wish, in the old days of DOS it was permitted byt boot sector viruses were very common and malicious so windows enhanced the security by not letting users to do that by them selves, and if you insist create a bootable floppy/CD with the program that you want to write on the boot sector and boot with this CD/floppy and your free to write whatever boot sector you want using a boot sector writing utility you must create, so as long as you are outside windows zone your free to do whatever you like to!

Hope this helps!

To follow the path, Walk with the MASTER, See through the MASTER, Be the MASTER!

I was just digging out some old books from under my bed and found Developing Your Own 32-Bit Operating System by Richard A. Burgess...it's a favourite of mine as well. Was wondering if he's updating it for the new 64 bit and multi-core processors.