You need to read, read, read. You need to know all about the low-level details of your hardware and you need to find out about basic OS theory. You'll need to be pretty competent at C-programming and/or assembler programming for your chosen CPU. (The assembler programming is a must, the C programming is optional but makes life much easier.)
And set aside about 5 years before you get a good stable working system. (Believe me, I speak from experience - I haven't managed to reach the "stable" state yet.) In the interim you will have learnt more about computers than most people will ever know.
Google "Writing your own OS" and you'll find quite a lot of useful information.