Thursday, October 13, 2016

How would I make my own OS?

Recently, a friend told me that his son wanted to build his own OS based on his own hardware design. He asked for my thoughts on how the son should start this endeavor. His son had found a lot of resources online where he could send in hardware designs and create fabrications based on his designs. The son wasn’t sure where to start or what to do next, but wanted to focus his efforts toward an Intel-like design. Rather than spend a lot of money up-front and possibly incur a lot of frustration, I suggested another route.

Without knowing the computer knowledge of his son, I suggested an approach of learning how programs work, how the OS works, and then down to hardware internals. Thankfully, a lot of these resources are free or low-cost and can utilize computers you may already have at home. The biggest investments into this endeavor are time and wanting to learn. It was fun to put this together and thought it would be a fun blog post!


Step 1: Learn C

The first topic to learn is the C programming language. Why C and not Python? Or Ruby? Or Go? Or X, Y, Z? Many software resources provide examples in C of how to interact with hardware. C is used in many places and a common way of doing things in a fast and portable manner. If you learn C, you can pick up C++, Java, C#, Python, and other languages that much easier. There are a lot of ways to learn C that available across the internet. One of the ways I learned C and I’m sure many other people was from the venerable K&R book available on Amazon.

C Programming Language


Step 2: Learn how popular operating systems work

With a good foundation of C, you are able to get a better idea of how popular operating systems work at the deeper technical level. When you start to dig into the internals of Linux and Windows, you see function calls, structs, and other programming concepts. Without a good foundation of programming concepts and how these things work, it can be overwhelming.

The first OS to learn more about is Linux. There are many free and supported ways to get current and older copies of various Linux operating systems to play with. To dig into Linux, I recommended these Linux internals resources:

Introduction to Linux: A Hands on Guide

[Update: A reader suggested "Linux From Scratch" as an additional method to learn Linux. Thanks David!]
Another way to learn Linux is to build it yourself! This site below walks you through the process to accomplish that.

http://linuxfromscratch.org/lfs/index.html



The second OS to learn more about is Windows. Microsoft Press puts out great resources to learn about a great deal of the internals within Windows. MSDN is also another resource to dive into after these resources below.

Windows Internals, Part 1 (Developer Reference)
https://www.amazon.com/Windows-Internals-Part-Developer-Reference/dp/B00JDMPHIG/ref=sr_1_3

Windows Internals, Part 2 (Developer Reference)
https://www.amazon.com/Windows-Internals-Part-Developer-Reference/dp/B00JDMPIDU/ref=sr_1_4


Step 3: Learn Intel assembly

At some point in time, learning assembly is going to be required to dive deep into the inner workings of an OS and hardware. There are many great resources to learn Intel x86 assembly, but the resources I refer to most often and to others are located at http://opensecuritytraining.info. The ramp-up with these videos to learn assembly as a beginner to tackling advanced concepts is well thought out and approachable. Plus, the resources (video and slides) are free! Like any complex topic, there are beginner, intermediate, and advanced sections.

Beginner: Introductory Intel x86: Architecture, Assembly, Applications, & Alliteration
http://opensecuritytraining.info/IntroX86.html

-- Companion book to purchase: Professional Assembly Language:

Intermediate:
Intermediate Intel x86: Architecture, Assembly, Applications, & Alliteration

Introductory Intel x86-64: Architecture, Assembly, Applications, & Alliteration
http://opensecuritytraining.info/IntroX86-64.html

Advanced:
Advanced x86: Virtualization with Intel VT-x

Advanced x86: Introduction to BIOS & SMM

There are many resources at Open Security Training that apply as well and you should check them out! In addition to those resources, the manuals from Intel are the best source to learn Intel assembly:

Intel® 64 and IA-32 Architectures Software Developer Manuals


Step 4: Learn Intel based hardware

With a solid foundation of C, OS internals, and how things work at an advanced technical level, it’s best to put that knowledge to work! Intel has a Raspberry Pi like board called the “Edison”. With the knowledge gained to this point, lots of interesting possibilities open up! You could write a simple application and analyze how that program works (similar to the DVRF blog series). There are lots of possibilities only limited by your imagination! The Edison runs on an Intel CPU and can run C programs that let’s you get down to a low level of programming if wanted.




Step 5: Do it!

With all of this knowledge gained, now it’s up to you to continue the journey. By now, you should have a great understanding of how complex systems in a computer work together. You can continue on to build an OS or join a project to maintain an OS and have a good idea of how to proceed. Going forward from here only continues to be fun!

No comments:

Post a Comment