Sign in to follow this  
BentmGamer

Create an operating system

Recommended Posts

BentmGamer    88
Herro. Im not sure if this fits in programming, but i have a question. I had a mind-blowing dream for an operating system last month, and i need to make a prototype. How would I go about doing that. Would i use flash or vbs or what? I would make a prototype like this guy:

[media]http://www.youtube.com/watch?v=1IxG6Su__n4[/media] Edited by Bentm's Games

Share this post


Link to post
Share on other sites
Narf the Mouse    322
...Y'know, I'd be interested in buying a good book on writing an OS, if anyone wants to write one and put it up on Amazon. I'd probably learn a lot from it, if nothing else.

...Not that writing a textbook isn't a massive project. Edited by Narf the Mouse

Share this post


Link to post
Share on other sites
Saruman    4339
[quote name='Narf the Mouse' timestamp='1351320533' post='4994357']
...Y'know, I'd be interested in buying a good book on writing an OS, if anyone wants to write one and put it up on Amazon.
[/quote]
You mean like Tenenbaum's books [url="http://www.amazon.com/Modern-Operating-Systems-Andrew-Tanenbaum/dp/0136006639"]Modern Operating Systems[/url] and [url="http://www.amazon.com/Operating-Systems-Design-Implementation-Edition/dp/0131429388/ref=pd_sim_b_1"]Operating Systems Design & Implementation[/url]? Or something more like [url="http://www.amazon.com/Design-Operating-System-Prentice-Hall-Software/dp/0132017997/ref=pd_sim_b_2"]Design of the UNIX Operating System[/url]? There are literally tons of them on Amazon! Edited by joew

Share this post


Link to post
Share on other sites
Narf the Mouse    322
[quote name='joew' timestamp='1351320790' post='4994358']
[quote name='Narf the Mouse' timestamp='1351320533' post='4994357']
...Y'know, I'd be interested in buying a good book on writing an OS, if anyone wants to write one and put it up on Amazon.
[/quote]
You mean like Tenenbaum's books [url="http://www.amazon.com/Modern-Operating-Systems-Andrew-Tanenbaum/dp/0136006639"]Modern Operating Systems[/url] and [url="http://www.amazon.com/Operating-Systems-Design-Implementation-Edition/dp/0131429388/ref=pd_sim_b_1"]Operating Systems Design & Implementation[/url]? Or something more like [url="http://www.amazon.com/Design-Operating-System-Prentice-Hall-Software/dp/0132017997/ref=pd_sim_b_2"]Design of the UNIX Operating System[/url]? There are literally tons of them on Amazon!
[/quote]
[quote name='ATC' timestamp='1351313891' post='4994344']
*Snip*

[b]And along the way it also gets very frustrating because there are virtually no resources available online or in book stores to help you.[/b]

*Snip*

Regards,

--ATC--
[/quote]
...Alright, which one of you is right? :) Edited by Narf the Mouse

Share this post


Link to post
Share on other sites
Ryan_001    3475
I wrote a small OS for a university project, even wrote the boot loader from scratch in assembly and did the rest in C++. Its not easy at all. When things go wrong you don't get a pretty screen with debug info, you get a 3 beeps and re-start and its back to scratching your head over the assembly trying to figure what went wrong. Also working with BIOS is an archaic and esoteric art in and of itself, with sparse documentation hidden in obscure areas of the interwebs. Though it is a learning experience, and one day I will revisit it and finish what I started ;) Good luck to you.

Share this post


Link to post
Share on other sites
Creating an OS is one of the hardest things ever.
However, if you want to create just a GUI, then pick a pre-existing OS - like a Linux distro - and write the GUI in something like C++.

Also, if you are serious about creating an OS, then I suggest you look at [url="http://wiki.osdev.org/Expanded_Main_Page"]this[/url]. It is a very useful resource, in my opinion.

Share this post


Link to post
Share on other sites
mrbastard    1577
[quote name='ATC' timestamp='1351313891' post='4994344']
As someone who's actually written a working OS before, I would recommend you don't even waste your time making this GUI "prototype" unless:

[indent=1]A) You already have experience and know how to write an OS[/indent]
[indent=1]B) You have not completed A, so you stop what you're doing to complete A... lol[/indent]
[/quote]

I'd add:

C) You're talking about a GUI setup that could be implemented as a windows manager on linux (for example). This is likely a tractable task for an individual, especially if an existing project is used as a starting point.
D) You feel you'd enjoy building the prototype.
E) By prototype you mean an interactive animation. This seems very clear to me from the OP's comment, but perhaps escaped some of you guys?

Share this post


Link to post
Share on other sites
SelethD    456
Perhaps I am off track, but from what I understood of the OP, is that he/she is wanting to know of some type of 'graphical' tools such as flash, to create the prototype. I dont think the OP is actually interested in 'coding' anything.
At least thats what I read into it. Although, I'm glad some good book titles were posted on the subject. I haven't done assm in a long long time, but reserch into writing a tiny os looks to be some interesting reading.

Share this post


Link to post
Share on other sites
Telcontar    1554
Just reading ATC's response scared the everliving shit out of me, and I was not (and never would) consider trying to build a new OS.

Well, I'm off to have nightmares of implementing malloc and free...

Share this post


Link to post
Share on other sites
BentmGamer    88
[quote name='SelethD' timestamp='1351343397' post='4994404']
Perhaps I am off track, but from what I understood of the OP, is that he/she is wanting to know of some type of 'graphical' tools such as flash, to create the prototype. I dont think the OP is actually interested in 'coding' anything.
At least thats what I read into it. Although, I'm glad some good book titles were posted on the subject. I haven't done assm in a long long time, but reserch into writing a tiny os looks to be some interesting reading.
[/quote]
Pretty much. What I want to do is create a sort of program that would act like the os. Then build and build and build on that. Then maybe make a virtual os. Once I would get more people working, I would eventually build a linux window manager, then after years (but probly not) possibly maybe consider consider consider maybe wantin to consider to almost amybe feel like considering to want to make a full fledged os. What I want to know is what program to use to make this program, and tutorials for it.

Share this post


Link to post
Share on other sites
It's much easier to make a program act as if it were a real operating system (to some sort) than an actual operating system(and a lot more bearable as well).

And I don't think your terminology of "virtual" to "real" operating systems makes sense.

An operating system running on a virtual machine is still a "real" operating system, as it would generally carry the same instructions that would be used otherwise on real hardware directly, rather than a program acting like a virtualized version of real hardware itself.

And if you're really that eager to see how they made the video, contact them on their YouTube account.

Someone else can propose an idea, guess, or maybe know, but it's hard to tell based on just a video as to what program was used to make it.

If you want to make an operating system for real, however, you have a lot of learning to do.

Even though an operating system is still software, it's not the same as compile-and-go "Hello world!" that can be accomplished and executed in less than a minute from scratch(with the right programs, input speed, files and knowledge ready).

Share this post


Link to post
Share on other sites
BentmGamer    88
[quote name='Pointer2APointer' timestamp='1351369156' post='4994505']
It's much easier to make a program act as if it were a real operating system (to some sort) than an actual operating system(and a lot more bearable as well).

And I don't think your terminology of "virtual" to "real" operating systems makes sense.

An operating system running on a virtual machine is still a "real" operating system, as it would generally carry the same instructions that would be used otherwise on real hardware directly, rather than a program acting like a virtualized version of real hardware itself.
[/quote]

That's what I want to do, create a program that would act as an interface. And by virtual, I mean something like what people make in vbs and call an os

Share this post


Link to post
Share on other sites
ATC    551
[quote name='Washu' timestamp='1351326247' post='4994367']
Actually, that address is a holdover of realmode, not protected mode. While still mapped (up to a point) when you switch to protected mode, it does not need to, nor usually will, remain mapped to that address range. Furthermore, if you have enabled paging then that code could be doing all sorts of nasty things to the byte at 0xB8000. Additionally, your code only affects a single byte of memory, and thus doesn't actually print your string so much as it puts '!' to the byte at address 0xB8000.
[/quote]

Yes, sorry, I screwed up my code... The original version I wanted to post from one of my first working OS kernels is this:

char* screen = (char *) 0xB8000;

const char* str = "Hello, OS world!\0";

for( int index = 0; str[index] != '\0'; ++index)
screen[index] = str[index];

[i][b]EDIT: I figured out why my code was getting screwed up... if you're using a variable named "i" as an array index the forums interprets it as italics lol! So now I fixed it so the code is correct. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img][/b][/i]

However, when I tried to post it with the code/source tags it came out screwed up and was unreadable (for some reason the forums don't like array indexing [x] symbols in code/source tags)! So I tried to modify it to make it readable using just pointer arithmetic but it looks like I actually just [i]screwed it up (never incremented "screen" so, you're right) lol. I will fix the original example; thanks for pointing it out! Was very tired last night! [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

And yes, you're right... it is real-mode. Sorry for that mix-up too! But I was simply demonstrating how physical RAM can be manipulated in Ring-0 without causing a crash, and how to make a basic "Hello world" kernel work. You obviously wouldn't want to use this code in a real/practical OS project. It's just a contrived example to make a point. ;) Edited by ATC

Share this post


Link to post
Share on other sites
Washu    7829
[quote name='ATC' timestamp='1351372879' post='4994527']
[quote name='Washu' timestamp='1351326247' post='4994367']
Actually, that address is a holdover of realmode, not protected mode. While still mapped (up to a point) when you switch to protected mode, it does not need to, nor usually will, remain mapped to that address range. Furthermore, if you have enabled paging then that code could be doing all sorts of nasty things to the byte at 0xB8000. Additionally, your code only affects a single byte of memory, and thus doesn't actually print your string so much as it puts '!' to the byte at address 0xB8000.
[/quote]

Yes, sorry, I screwed up my code... The original version I wanted to post from one of my first working OS kernels is this:

char* screen = (char *) 0xB8000;

const char* str = "Hello, OS world!\0";

for( int index = 0; str[index] != '\0'; ++index)
screen[index] = str[index];

[i][b]EDIT: I figured out why my code was getting screwed up... if you're using a variable named "i" as an array index the forums interprets it as italics lol! So now I fixed it so the code is correct. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img][/b][/i]

However, when I tried to post it with the code/source tags it came out screwed up and was unreadable (for some reason the forums don't like array indexing [x] symbols in code/source tags)! So I tried to modify it to make it readable using just pointer arithmetic but it looks like I actually just [i]screwed it up (never incremented "screen" so, you're right) lol. I will fix the original example; thanks for pointing it out! Was very tired last night! [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

And yes, you're right... it is real-mode. Sorry for that mix-up too! But I was simply demonstrating how physical RAM can be manipulated in Ring-0 without causing a crash, and how to make a basic "Hello world" kernel work. You obviously wouldn't want to use this code in a real/practical OS project. It's just a contrived example to make a point. ;)
[/quote]
Well, the bad news is, that code is STILL wrong.

The text screen video memory at that address takes WORDS, not bytes. Each word is a combination of a character to display and an attribute describing the color of the character and its background.

Share this post


Link to post
Share on other sites
ATC    551
[quote name='Washu' timestamp='1351373953' post='4994533']
Well, the bad news is, that code is STILL wrong.
The text screen video memory at that address takes WORDS, not bytes. Each word is a combination of a character to display and an attribute describing the color of the character and its background.
[/quote]

Ah, got me again... Oddly though, using char* did work, but in the real code I was padding it with the color information to write 16-bits for each char... But I looked at my text I/O implementation of a more mature version of my system project and saw that I actually used type [i]unsigned short*[/i], so you're correct. It's been a couple years though, like I said... so my memory of some things is a bit faded. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Anyhow... about learning resources... It [i]is[/i] indeed true that there are plenty books on OS development. But very few (in my experience) were suitable for beginners and even fewer actually teach [i]how[/i] to write your first OS. Most books assume you're a CS major with system's programming experience and teach about OS design/architecture as opposed to the "how" and "why". So as a beginner OS programmer it's extremely difficult to find the learning resources you need. It's been a couple years since I did my OS project, so maybe things have changed; but that is the way I remember it.

[quote name='Telcontar' timestamp='1351345771' post='4994410']
Just reading ATC's response scared the everliving shit out of me, and I was not (and never would) consider trying to build a new OS.

Well, I'm off to have nightmares of implementing malloc and free...
[/quote]

Well, I didn't mean to scare ya lol! [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

It's actually a [i]lot[/i] of fun... and the feeling of [u][i]overwhelming satisfaction[/i][/u] you get from making the damn thing work for the first time was one of the most rewarding programming experiences I've ever had. Writing you own CSTDLib functions like malloc and free is also extremely rewarding. It's difficult and frustrating to get through it but when you get it working correctly you will be extremely happy and proud of yourself. Each time you call malloc or free you'll be grinning ear to ear knowing [i]you[/i] made that code work. :-)

Even the little things like rolling your own strlen or strcmp functions are fun:

[source lang="cpp"]
// Naive approach; just an example ::
size_t strlen( const char* str ) {
size_t len;
char* ptr = (char *)str;

for( len = 0x00; *ptr != '\0'; ++ptr, ++len ) ;

return len;
}
[/source]

Seriously, you should try your hand at it! It's really challenging and entertaining to roll your own standard lib and try to write optimal routines and functions. And you'll walk away knowing 1000 fold more about C, C++, assembly language, the standard libraries and computer science.

One thing that was unique about my OS project is that I developed it completely within Visual Studio 2008 (Pro). Yes, you can indeed write an OS in Visual Studio! It's all about configuring the environment and project settings correctly, and either writing your own bootloader capable of handling your kernel/loader or implementing the multi-boot standard to make your OS interoperable with a good bootloader like GRUB.

I chose the latter approach, and used GRUB. And my kernel was actually a PE image (.exe file). The way I achieved interoperability with GRUB was by setting the base address of the PE image to the system loader's entry point, and using some assembly language tricks to emit the multi-boot header right there where GRUB would be expecting it. For example:

[source lang="cpp"]
#define dd(x) \
__asm _emit (x) & 0xff \
__asm _emit (x) >> 8 & 0xff \
__asm _emit (x) >> 16 & 0xff \
__asm _emit (x) >> 24 & 0xff
[/source]

That macro will actually embed a dword right into the code. So you can do this:

[source lang="cpp"]
int _loaderMain( )
{
dd( MB_MAGIC_NUMBER );

// ... and so on ...
}
[/source]

I also went so far as to write an entire static lib for handling PE images and reading their headers which could be linked right into the kernel or anything else that needed it. I implemented drivers as DLLs with a special *.DRV extension, and the OS loader (an intermediate loading program loaded by the bootloader that loaded the kernel and critical drivers) could us the "PELib" to read the kernel and driver headers. Just talking about it kinda makes me want to start playing with it all again, but I've got an engine to write lol. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Regards,

--ATC-- Edited by ATC

Share this post


Link to post
Share on other sites
ATC    551
To demonstrate what Washu is talking about, a correct example of what I was trying to demonstrate earlier would be more like this::

[source lang="cpp"]
void _writeText( const char* str ) {

int index = 0x00;
char* pstr = (char *)str;
unsigned short *vidMem = (unsigned short *)0xB8000;

for( ; *pstr; ++pstr, ++index )
{
unsigned char c = *pstr;

vidMem[index] = (unsigned short) c | 0x0700;
}
}
[/source]

Sorry for screwing this up multiple times trying to make a simple point lol... Like I said, it's been years and I can't copy code from any of my projects verbatim because there's a lot of code, headers, macros and functions used in numerous files and it wouldn't make sense without posting it all (overkill for such a small, contrived example). So I just have to either try to strike up examples from memory or write a new, simplified version; as it so happened I did that wrong, lol... :P

Hopefully this time I did the demonstration correctly haha

Share this post


Link to post
Share on other sites
BentmGamer    88
[quote name='ATC' timestamp='1351375662' post='4994548']
To demonstrate what Washu is talking about, a correct example of what I was trying to demonstrate earlier would be more like this::

[source lang="cpp"]
void _writeText( const char* str ) {

int index = 0x00;
char* pstr = (char *)str;
unsigned short *vidMem = (unsigned short *)0xB8000;

for( ; *pstr; ++pstr, ++index )
{
unsigned char c = *pstr;

vidMem[index] = (unsigned short) c | 0x0700;
}
}
[/source]

Sorry for screwing this up multiple times trying to make a simple point lol... Like I said, it's been years and I can't copy code from any of my projects verbatim because there's a lot of code, headers, macros and functions used in numerous files and it wouldn't make sense without posting it all (overkill for such a small, contrived example). So I just have to either try to strike up examples from memory or write a new, simplified version; as it so happened I did that wrong, lol... [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Hopefully this time I did the demonstration correctly haha
[/quote] Guys, guys, guys. Calm down. I dont need this info (but thanks and you are some smart peeps) all i need to know is how to make a program that i could add buttons animations and interactive objects into so it will give the illusion of being an os. I need this to test usability, and help my ability in coding and other software. So far REAL studio seems like my best bet, any suggestions

Share this post


Link to post
Share on other sites
mrbastard    1577
Your original suggestions of flash or svg would work fine for a mock-up. If you want advice on how to practice coding, you're going to have to say what sort of level you want to code at and what languages you're familiar with.

Share this post


Link to post
Share on other sites
ATC    551
[b]@ Shrinkage ::[/b]

Very good and interesting post... I +1'ed it!

However, I'd like to point out a few things... For starters, while your idea is great and makes me want to try it myself, which of the two is cheaper: [b]1) [/b]free download of Sun's Virtualbox and/or free download of Microsoft's Virtual PC [b]2)[/b] going out and buying physical hardware like you describe? Obviously, #1 is a lot cheaper and more accessible for "the crowd". Secondly, most of us programmers are writing software for x86/64 systems. And when we want to learn about OS development it's usually [i]not [/i]to try to become a professional OS developer (very tough market to get into, dominated by Microsoft) but to go on an "academic" venture; to become more knowledgeable and skillful programmers on our primary development platform. So for those two reasons alone I would not go as far as saying that the x86 platform is a "horrible" choice... I think that if you're in OS development for academic reasons you should work with the platform you do most of your userland/everyday programming on... and if you're in it to make a profession out of OS development you should work with the platform you intend to support.

However, I must agree that learning the x86/64 architecture is quite difficult; the learning curve is steep, the manuals are thick and Intel is not exactly what I'd call a "n00b-friendly" company lol. There are lots of little tricky caveats, traps and pitfalls... lots of weird things you must learn, like setting up a GDT (global descriptor table) as an off-the-wall example... But if you learn this stuff you walk away knowing what makes your PC and your primary OS (be it Windows, Linux, etc) tick. It's hard to even describe in words how incredibly valuable that can be to a PC programmer... say you're writing an performance-critical function that needs to move and/or compare large blocks of memory as quickly as possible. Without experience in low-level/systems programming, you're like to just to take the most direct, straight-forward (and naive) approach to your algorithm. With such experience, however, you know how the CPU, data bus and RAM work... you know how memory is moved in/out of registers, to and from RAM and understand virtual memory and paging/caching... you would also know that on 32-bit architecture the CPU registers are 32-bits in size and natively move d-words (32-bits of data) faster than it can move 64-bits (and vice-versa on x64 platforms). Armed with that sort of knowledge you will almost always know how to implement the best possible routines. However, if you're a PC programmer by trade and all your OS development experience is on some completely different platform there can be quite a few gaps in your knowledge...

So I encourage people to work with the platform that's right for them... and if you're a PC developer then you may as well bite the bullet and learn the x86/64 platform. If, however, you are wanting to make a career or serious hobby out of OS dev then choose the platform you need to work with and heed Shrinkage's advice... and learn more than one platform!

Regards,

--ATC--

Share this post


Link to post
Share on other sites
Ohforf sake    2052
I wrote my first OS (multithreading, virtual memory, rudimentary syscalls) on an ARM SoC at university, so there are cheaper ways to get access to this kind of rig. Although we didn't have JTAG or a logic analyzer. IMSW we had a serial cable and a LED, which is not as comfy but still enough.

I never tried writing an OS for x86 so my comparisons might be wrong here, but the ARM ISA (I used ARMv4) is a lot nicer then x86 ISA and you can not avoid writing some parts in assembly. Also in our chip, we could disable certain functionalities (cache, MMU, ...) in order to get everything right one step at a time. I don't know, if intel lets you globally disable the caches "just like that".

So for the very first steps in OS programing I'm with Shinkage. Get yourself an ARM SoC or find someone who lets you work with his. A university course is even better because you get help when you are stuck. If afterwards, you still want to write OSs and maybe do something bigger, then you can still go x86 (or whatever platform is your favorite).

Share this post


Link to post
Share on other sites
alh420    5995
[quote name='ATC' timestamp='1351407231' post='4994646']
Very good and interesting post... I +1'ed it!

[Lots of text]
[/quote]

The point with the simple system is that everything you learn is actually directly applicable on the more complex x86 system.
Sure, ports memory areas and bitpatterns isn't the same, but thats not really the interesting part of it...
Thats just whatever the hardware is right now, and should (mostly) be handled by drivers, working as plugins to abstract hardware so the OS doesn't have to care about those details.

With simpler hw you can focus better on the actual OS programming problems.
Then when you've got those down, you can move onto more complex hardware.
Doing it on an actual physical device is a bit more rewarding imo.

My first programming steps was taken on a hacked Texas Instruments calculator, running z80 (Ti83) and 68000 (TI89) assembler.
There wasn't even a c-compiler available, very good experience for learning how a computer system works [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Old iPods are also fun hardware, its basically a SoC with a nice screen and some buttons, and they are pretty easy to upload your own bootloader and code to, I've played a bit with my old (2006) iPod NANO and installed linux on it. (and run some OS-less code too)

So theres lots of options if you dont want to spend money on a beagle board, though with those you get the advantage of good documentation and a big community.

OP: Sorry for all this off topicness [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Olof Hedman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this