Programming a 64-bit Operating System


Before progressing any further I would ask you to read my Privacy Policy.

Note: Those of you who have visited this site before should be aware that I have recently made considerable changes to the code and the documentation, so you may want to download the source again. Have a look at at the blog for more details.

Soon after the AMD Athlon64 was released I bought a computer incorporating one with the intent of learning its assembly language. It took some time, but I finally got around to a little experimenting. Although AMD make their excellent Programmer's Manuals available on-line for free, I found it very difficult to find other information. Specifically I could have done with some simple examples showing how exactly to get the processor from reset to long (i.e. 64-bit) mode. Plenty of sites give this sort of detail for protected mode on the i386 but I couldn't find much about the x86_64 processors.

After much experimentation, and many false leads, I managed to figure it out so I thought that it might be useful to others if I described what I came up with. The title above is a bit of a misnomer - only by a very wide stretch of the imagination could my system be described as an "operating system", but it does boot, multi-tasks simple programs, and even has rudimentary keyboard and IDE hard disk device drivers.

I never had any intention of producing a true OS. There are plenty of those about and it would be a very foolish, or vain, person who thought that they could compete with the likes of FreeBSD and Linux. But my interest in computers isn't practical; I just find programming them, particularly at this level, to be a supremely satisfying intellectual pursuit. Some people enjoy crossword puzzles or Sudoku; I enjoy assembler programming. Every new processor that I experiment with is a new delight.

Whatever, before you can get to grips with the CPU you're going to need the appropriate documentation and tools.

Documentation
Tools

Here's a gzipped tar of the source for this project; untarring this will create a directory IanOS containing all the source files and a makefile. This assumes that you are using the gcc toolset. Before looking too closely at the code you'll probably want to check out:

Assembler Syntax

Here are instructions for building and running the system. Now let's look at the code itself:

The Code

(Before reading about the code you may wish to have a quick look at this note about the online source code.)

Note: If anybody wishes to use any of this code in their own project, please do so. Credit would be nice but, if not, no matter. Note that the boot sector code is strongly modelled on that in Developing Your Own 32-bit Operating System.


Please feel free to contact me about any aspect of this project.

Alternatively, post a comment in my Guest book.

If you are interested - About Me.

I thought that it might be fun to start a blog where I can describe my thought processes, problems, and development of IanOS. You can look at it here.