The book, "Operating Systems: A Design-Oriented Approach", by Charles Crowley, does just what it sounds like. It shows you how operating systems work by providing sample C++ code for a simple one. You could probably take the basic ideas from there and improve upon them.