Like kornman said what you want to do is easily done in OS.

Don't look to incorperate code in to OS, simply code in OS. Work out how it runs, what does what. Then incoperate your theory into OS.