Want to develop my first operating system

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Seahorse
Member
Member
Posts: 64
Joined: Sat Dec 03, 2016 3:13 am

Want to develop my first operating system

Post by Seahorse »

I have messed around with some Python crap, but I want a really fun project. I want to learn C or ASM. What are some good resources for both that you can recommend? Is the ANSI C book by K&R still good? As for virtual machine, I have Xubuntu Linux installed on one.
User avatar
sleephacker
Member
Member
Posts: 97
Joined: Thu Aug 06, 2015 6:41 am
Location: Netherlands

Re: Want to develop my first operating system

Post by sleephacker »

Getting Started is a good page to read.
Real mode assembly I is a good place to start for asm, also google: "x86 + unknown_instruction" is a good way to learn, and I personally really like this page as well.
For C development I think the Bare Bones tutorial might be a good place to start.
More tutorials can be found on the Tutorials page.
If you're looking for books, there is a wiki page about that, as well as a forum thread.

And, not to be mean but because you're asking about things already described on the wiki, you might what to read How To Ask Questions as well, especially the part under "Research".
User avatar
crunch
Member
Member
Posts: 81
Joined: Wed Aug 31, 2016 9:53 pm
Libera.chat IRC: crunch
Location: San Diego, CA

Re: Want to develop my first operating system

Post by crunch »

A lot of people are going to tell you that this is a bad way to learn C. And they may be right. But don't let that stop you.

I had never written a single line of C when I first came to this board many years ago. It's a steep learning curve, but this kind of project really gives you a deep understanding of the language.

I'd recommend doing a couple fun user land programs first, so that you can learn and debug in a more user-friendly environment than an emulator.
User avatar
Seahorse
Member
Member
Posts: 64
Joined: Sat Dec 03, 2016 3:13 am

Re: Want to develop my first operating system

Post by Seahorse »

crunch wrote:A lot of people are going to tell you that this is a bad way to learn C. And they may be right. But don't let that stop you.

I had never written a single line of C when I first came to this board many years ago. It's a steep learning curve, but this kind of project really gives you a deep understanding of the language.

I'd recommend doing a couple fun user land programs first, so that you can learn and debug in a more user-friendly environment than an emulator.
Where did you learn actual C though?
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Want to develop my first operating system

Post by Ch4ozz »

I actually learned C by creating hacks for games when I was 14 and coding my own games using 3D Gamestudio (when I was 12).
Never read one book about it and also learned ASM while hacking games.
If you want to be a lil bit faster then me you should read some tutorials and then create some useful programs first.
You actually learn alot of asm when you do some easier crackmes (plus its alot of fun too)
Even writing shellcode is alot of fun. But hes actually right - you shouldnt learn C by coding your own OS because you will hate it some months later and have to recode it completely.
Start on your current OS and do some usermode apps as he suggested to learn the basics so you dont have to rewrite the OS completely later :)
User avatar
crunch
Member
Member
Posts: 81
Joined: Wed Aug 31, 2016 9:53 pm
Libera.chat IRC: crunch
Location: San Diego, CA

Re: Want to develop my first operating system

Post by crunch »

Ch4ozz wrote:I actually learned C by creating hacks for games when I was 14 and coding my own games using 3D Gamestudio (when I was 12).
Never read one book about it and also learned ASM while hacking games.
If you want to be a lil bit faster then me you should read some tutorials and then create some useful programs first.
You actually learn alot of asm when you do some easier crackmes (plus its alot of fun too)
Even writing shellcode is alot of fun. But hes actually right - you shouldnt learn C by coding your own OS because you will hate it some months later and have to recode it completely.
Start on your current OS and do some usermode apps as he suggested to learn the basics so you dont have to rewrite the OS completely later :)
This is true. I didn't even follow my own advice, and pretty much learned C by reading/writing some osdev tutorials. And sure enough I ended up rewriting the entire OS once I actually stepped back to write some userland code 8) (and a maybe another time after that!)

As far as where to learn... if you already have a strong background in other languages - you mentioned python - then many of the basics will be the same, i.e. for loops, conditionals, variables, etc. The major hurdle (and the source of power) in C is pointers. You NEED to know pointers as well as you know the back of your hand if you want to have any chance of doing something significant in C.

Here's a decent article explaining some pointer basics: http://karwin.blogspot.com/2012/11/c-po ... eally.html
User avatar
Seahorse
Member
Member
Posts: 64
Joined: Sat Dec 03, 2016 3:13 am

Re: Want to develop my first operating system

Post by Seahorse »

Honestly, I don't know if I'm ready for this yet based on these replies I got. Sure, I messed around with some code, but couldn't really execute an actual project. I would love to, but I just have trouble executing things (computer pun not intended :D ).

I really need to understand.
alexfru
Member
Member
Posts: 1118
Joined: Tue Mar 04, 2014 5:27 am

Re: Want to develop my first operating system

Post by alexfru »

crunch wrote:The major hurdle (and the source of power) in C is pointers. You NEED to know pointers as well as you know the back of your hand if you want to have any chance of doing something significant in C.
One should also know undefined behavior, so it doesn't come as a surprise why perfectly looking code isn't working / why the compiler "breaks" it.
User avatar
Seahorse
Member
Member
Posts: 64
Joined: Sat Dec 03, 2016 3:13 am

Re: Want to develop my first operating system

Post by Seahorse »

I am starting to wonder if any programming (let alone system programming) is for me.
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: Want to develop my first operating system

Post by matt11235 »

Mark12 wrote:I am starting to wonder if any programming (let alone system programming) is for me.
Don't give up, you'll figure it out eventually :)
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
User avatar
jojo
Member
Member
Posts: 138
Joined: Mon Apr 18, 2016 9:50 am
Libera.chat IRC: jojo
Location: New York New York

Re: Want to develop my first operating system

Post by jojo »

Personally, when I started doing hobbyist OS stuff I already knew enough C to be dangerous and ended up actually learning it properly as I worked on my OS project. It worked okay for me, so I'd recommend the same for you -- because you can feel free to try if you're up for the challenge, but if you don't already know how to use a C compiler to make something executable then it's going to be incredibly aggravating to try and figure it out as you go with the tutorials on the wiki.

I would recommend a straightforward interactive tutorial series like this to get started learning C at all: http://www.learn-c.org/

Also, K&R is a pretty good reference if you already know C, but I wouldn't recommend it as a beginner's learning tool. For that, I would actually with a completely straight face recommend something like C for Dummies (my first exposure to C was C++ for Dummies, which was great, but at 11 I just couldn't wrap my head around OOP).

So here's what I would recommend:

1. Learn C using something like the tutorial series above along with a beginner's reference book like C for dummies. (already knowing python should make picking up the concepts way easier, so it shouldn't be too bad. The hardest parts will be all of the features that C is lacking compared to python and understanding how C actually produces machine code as opposed to the dynamic interpreted nature of python)

2. Once you're starting to feel comfortable getting into C, if you don't have one already either install a Linux distro on a spare machine or in a VM and get familiar with using GCC and the actual C toolchain in an actual local development environment (there's C compilers for every machine and OS you can think of, but Linux is by far still the most convenient platform for building things in C)

3. Think of some silly but nontrivial project to build in C on your own from scratch (a little game using SDL, maybe even a webapp using KORE.io, whatever you want as long as it's more advanced than a couple of functions in a single source file) and spend like a month of weekends implementing the thing. This will give you valuable insight into how really implementing and designing software in a systems language like C works in a way that nothing else can teach you, and it'll familiarize you more in practice with how the building and linking system in C works.

4. Somewhere in/between steps 2 and 3 above, start doing some research into how the CPU in your computer really works using wikipedia and google which should help you turn up some stuff like: https://www.youtube.com/watch?v=H4Z0S9ZbC0g -- learn the basics of how the CPU is connected to memory and peripherals, how it communicates, reads and writes to them, how it starts up and reads instructions, what registers and the stack are and how they're used, so that you can:

5. Start learning x86 assembly code. Besides manually twiddling bits with a hex editor, this is the lowest level way to write code for your CPU and you *WILL* need to know it to do things in your OS that C has absolutely no concept of, Ex: setting up special registers to configure the processor to work the way you want, setting up memory management, writing to I/O ports, ETC. You need it to do a lot of little glue stuff, and either way you're going to want to know how your computer operates if you're writing the software that makes it go. And it goes hand-in-hand with 4 as learning assembly will teach you about the machine and learning about the machine will make assembly make more sense. This seems like a really in-depth resource: http://opensecuritytraining.info/IntroX86.html

6. Roll up your sleeves and do what a real production dev does: With your wits and your new knowledge of the x86 architecture and C in one hand and google and the wonderful resource that is the OSDev wiki in the other, start at the start and decide a goal at a time what you want to accomplish (first: figure out how the PC boots code and get some boot code running on the bare hardware, second: learn how the keyboard controller works and get some code running that can handle some basic input...) and then use your resources and your intelligence to make it happen. Most of writing an OS is learning how the devices you want to interface with in your computer work one by one from datasheets and other resources and then hacking and debugging away with that information in mind until things start working. The rest is your imagination, really.

It's a long road, it will be frustrating, but it's worth it, it's equally rewarding, and you can do it! Remember this hilariously ironic anti-advice that I want to say is from It's Always Sunny: "Why keep doing something if you're not instantly great at it?"
User avatar
Seahorse
Member
Member
Posts: 64
Joined: Sat Dec 03, 2016 3:13 am

Re: Want to develop my first operating system

Post by Seahorse »

Haha. I actually almost purchased C++ For Dummies the other day. Thanks for breaking it down for me.
User avatar
MichaelFarthing
Member
Member
Posts: 169
Joined: Thu Mar 10, 2016 7:35 am
Location: Lancaster, England, Disunited Kingdom

Re: Want to develop my first operating system

Post by MichaelFarthing »

Mark12 wrote:Haha. I actually almost purchased C++ For Dummies the other day. Thanks for breaking it down for me.

No no no no no....
C for Dummies not C++ for Dummies..

C++ is a MUCH bigger learning task and is a lot further away from the machine architecture. Stick with strictly C.
User avatar
jojo
Member
Member
Posts: 138
Joined: Mon Apr 18, 2016 9:50 am
Libera.chat IRC: jojo
Location: New York New York

Re: Want to develop my first operating system

Post by jojo »

I get the impression that he actually read my post while you did not.

Anyhow I'm sure that was just a big ramble, but I'm glad if I was of any help, Mark. Best of luck! Or, actually, I prefer the Japanese 'ganbarimasu!' -- It's used like english speakers use 'good luck', but literally means something more like 'do your best'. Because, while there's an element of luck to most anything, your perseverance is something you can actually control.

I'm not a weeb, I swear.
User avatar
Seahorse
Member
Member
Posts: 64
Joined: Sat Dec 03, 2016 3:13 am

Re: Want to develop my first operating system

Post by Seahorse »

Yes, I'm just a dude who wants to someday (at the very least) make a console prompt along the lines of "[name]>_" and it will be all retro-looking. :D
Post Reply