Sign in to follow this  
Hassanbasil

Creating a simple operating system

Recommended Posts

Hello everyone,

I want to make a game console (like PS or xbox etc) for myself, so i thought, what would i need? a screen to show the game, the screen needs something to send it data, which is the processor, and since i have an old motherboard, i thought that i could make a simple operating system for it, that could just interface with usb devices and the screen, and do some operations to get the game running, hope it's possible and simple as i could think it is

as for the joysticks and all that - i can create them and make them connect via usb, and i'm going to store games on a flash drive which can be modified by a normal computer
as for the games that runs on the console - i think that's pretty much related to the OS itself, so i'll leave it for later
as for knowledge, im experienced with C (and most of C++) and good at electronics, and i'm ready to learn assembly if that's a must

but i'm somewhat confused, i don't know where to start - i know it might take hours, hundred of hours, or even thousand or more, which doesn't bother me at all
so where do i start?

thanks for reading.

Share this post


Link to post
Share on other sites
The easiest way to do this would be to take the linux kernal and start adding whatever you need on top of it, creating a super-minimal linux distro to do what you want. I would advise against writing your own kernel from scratch, mostly because modern standards like USB are pretty complex.

If you want to write a minimal OS from scratch (write your own kernel), you'll have a much easier time reading joysticks through the old game port (if this board is old enough to have one). You can bootstrap a PC and read the keyboard/write to the screen with pretty little work. If you need to read/write from a proper filesystem, or interface with USB joysticks, that's where it'll get complicated. (Don't worry about USB keyboard; on most PCs the USB keyboard is emulated by the BIOS to look like an old ps/2 keyboard)

This link will show a preview of what kind of trouble you're asking for :)
[url="http://en.literateprograms.org/Hello_World_(IBM_PC_bootstrap)"]http://en.literateprograms.org/Hello_World_(IBM_PC_bootstrap)[/url]

Share this post


Link to post
Share on other sites
There's no sense reinventing the wheel just because. Start by building a custom Linux kernel for the machine that boots straight into a custom 'game', without any of the Linux desktop trimmings. That alone should be a good first step.

Share this post


Link to post
Share on other sites
Well, you might want to read this:

[url="http://www.brokenthorn.com/Resources/OSDevIndex.html"]http://www.brokentho...OSDevIndex.html[/url]

It's a very thorough tutorial on OS development. You'll need to learn ASM.

Share this post


Link to post
Share on other sites
Thanks for the links - helped me really much.

though i'm stuck at some point: i can't seem to be able to get my bootloader on the first sector of a virtual floppy disk (made it using VFD (virtual floppy drive)), i got this basic asm code:
[code]
;*********************************************
; Boot1.asm
; - A Simple Bootloader
;
; Operating Systems Development Tutorial
;*********************************************

org 0x7c00 ; We are loaded by BIOS at 0x7C00

bits 16 ; We are still in 16 bit Real Mode

Start:

cli ; Clear all Interrupts
hlt ; halt the system

times 510 - ($-$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0

dw 0xAA55 ; Boot Signiture
[/code]

compiled via nasm and the created bin seems right (2 bytes at beginning, and 2 bytes signature at ending)

so i did this:
in command prompt:
debug c:\boot.bin
-l 0
-w 0 0 0 1 <-- here

i get an error by windows saying:
title: "16 bit MS-DOS subsystem
"Drive A: . Unable to lock for exclusive access. Another application may be using the drive. When the other application has finished using the drive you may retry the operation. Choose 'close' to terminate the application." -close- -abort- -ignore-

perhaps, i can't write to a virtual disk?
well i followed the above link's tutorial which used an application called partcopy, it also said that i cannot write to destination at offset 0

what could be causing this? how can i solve it?

Share this post


Link to post
Share on other sites
I have written some simple multithreaded kernels in C++ in the past, and, more recently, I was involved in the RenrakuOS project, which was a project to build a managed (.NET/Mono) OS in 100% Boo (ok ok, some compiler magic was needed to spit out assembly when we needed low level control - basically, certain methods of certain objects were transformed to specific assembly sequences (think compiler intrinsics on a class level)). I also have a little experience with programming for microcontrollers (my most recent project being the firmware for [url="http://www.djtechtools.com/forum/showthread.php?t=28014"]this[/url]).

First, don't even bother thinking you could compete with current-gen (or previous gen) consoles. Its just not a realistic goal. (Since you mentioned PS and xbox)

Having said that, depending on what your goals are, you do have a few options:
[list][*]Write a gaming OS for existing computers (PC/mac) - I wouldn't really recommend it. Its a lot of work and you will have a lot of trouble trying to support certain hardware, eg, graphics cards, because most manufacturers simply do not release enough documentation. You could limit your graphics card support to Intel cards, for which decent open source drivers exist, and then port those to you OS, but it will still be a lot of work and you'll be missing out on the latest and greatest AMD and Nvidia offerings. Either way, it will be a huge amount of work to build a custom OS. If you DO decide to go this route, I would advise against using C or assembly in favor of building a managed OS, built on top of either .NET of the JVM as it will greatly increase the speed at which you get stuff done, plus if you do it right, makes porting existing code easy and may even let you use existing tools (eg, for Renraku, we were able to use the Microsoft .NET debugger - very very useful!)[/list]
[list][*]Base your OS on Linux and use Linux-compatible hardware. This is the route I'd go if I were to do such a project. If your system will run on generic PC hardware, you can make use of existing Linux drivers for things like graphics cards - including AMD and Nvidia cards! If you don't want to go the PC hardware route, then you still have a few good options, for example, basing your console on a BeagleBoard or PandaBoard would be a good start. The PandaBoard features a very fast ARM Cortex A9, running at 1GHz, with 1 GB of RAM and an onboard DSP for graphics acceleration. The graphics accelerator won't come anywhere close to a current-gen console or PC GPU, but it is pretty powerful nontheless (capable of OpenGL ES, 1080p HD video etc). The PandaBoard also has a bunch of functionality baked in (wifi/ethernet, expansion headers, SD Card, USB, VGA/HDMI output etc) and is priced at a very reasonable US$175. Finally, you can run Ubuntu, Meego and Android on it - all of which would make a reasonable base for a console OS.[/list]
[list][*]Finally, you could build your own console from scratch (if you ave the technical skills) or based around an existing hardware kit. You will not be able to compete with any recent hardware, but you could build something on par with a SNES or Genesis, with enough effort. A good start would be to get an [url="http://www.xgamestation.com/view_product.php?id=32"]XGameStation[/url] or [url="http://www.xgamestation.com/view_product.php?id=33"]HYDRA[/url] or [url="http://www.xgamestation.com/browse_products.php?category=9"]Chameleon[/url] (I own a 16bit Chameleon and its great!) The HYDRA is based around the Propeller microcontroller from Parallax - an 8 core microcontroller running at ~20MHz. This would be a pretty cool option and you are guaranteed to learn a LOT about hardware, software, video generation, audio generation etc etc. But, like I said, about the best you could compete with is a late 80's/early 90's console.[/list]

I personally wouldn't bother with the first option (PC hardware), but, if all you want is to get something working for yourself, this may be a simple option. Basically, you would build a bare-bones PC and attach existing peripherals either through USB, like you said, or through the serial port. You can then write a custom OS (or, much more realistic for the reasons I mentioned above, base it on Linux). You could, for example, configure Linux to give you a simple menu to select which game (stored on a memory stick or SD card) you want to play and then run it in full screen. A lightweight and simple window manager, like [url="http://www.google.ie/url?sa=t&source=web&cd=1&ved=0CBQQFjAA&url=http%3A%2F%2Faerosuidae.net%2Fmusca.html&ei=3PWpTbSHG8mwhAfsgIHXCQ&usg=AFQjCNGkpDEM32_MsBad0pdv9qZ9fkkvew"]Musca[/url] would be a good way to achieve this (Musca is very minimal and very easily controlled through scripts or external programs - exactly what you want!) Hardware modding is probably not realistic with PC hardware (other than itnerfacing through serial or USB).


Buying a beagleboard or pandaboard is also a very effective way of getting started quickly, lets you write 3D games, lets you connect USB devices and is very mod-friendly (extension pins, UART/SPI/I2C connectors, etc). You would probably still want to base it on Linux, so that you don't have to worry about the low low level details like accessing the graphics accelerator.

So, in summary, I would go with either option 2 (BeagleBoard or other EXISTING hardware + Linux, possibly modded) or option 3 (microcotnroller based NES/SNES/Genesis/Gameboy clone).

In any case, good luck.

[quote]
[color=#1C2837][size=2]i can't seem to be able to get my bootloader[/size][/color]
[color=#1C2837][size=2][/quote][/size][/color]
[color=#1C2837][size=2]I would recommend NOT writing your own bootloader. It really doesn't help you achieve your goal at all. Just use GRUB to boot your kernel and be done with it. Really, nothing your own bootloader will do will be much different from existing bootloaders. The interesting work begins in the kernel anyway, not the bootloader.[/size][/color]

Share this post


Link to post
Share on other sites
thanks for the detailed post - some points seems to be misunderstood, i don't want to compete with anything, even though it's possible (i don't know why you are so disappointed about it :P) all i want is creating an OS that can read a USB or a DVD or even hard disk, and it might not even be a game console if it's unrealistic as you said.

the whole thing is that i wanted to draw graphics on a monitor - it started when i ordered an arduino (didn't arrive yet, bad service x(! ), saw some vids on youtube that i could use an lcd with it (my order also included a small lcd (no colors)), so i'm going to play with it and use it for some mini project i have, but now i thought, if that small chip is able to use a small lcd (128x64 or something) wihout being too slow (the processor is at 16MHz), why don't i use a computer processor, which is much faster (2GHz?) to display more complex graphics on larger screens? alright - i thought that i wouldn't need a gfx card and calculate everything on the CPU because the OS will be simple and all the processor's power will be used only for this app, so it would be sufficient (hope i'm not mistaken :/ ), since i can't solder the computer processor on my own board, which would require much planning and experience (which i don't REALLY have), i thought that i should just use the motherboard as if im running a normal PC but with my own very simple OS

even if that's a terribly bad idea, i would really love to try, and it will be a very good challenge for me to write an OS, even if it's simple, it's great to learn and experiment something new.

ok well, now some comments here and there scare me about the OS, yet i don't see why it's that HARD - i personally thought that it's hard because you have to use assembly in everything, but now i found out that only the boot loader should be in assembly, which can just be simple enough to load a kernel which is in C, and nothing's hard in C!, so is the kernel responsible for EVERYTHING after it was loaded by the bootloader? and the bootloader is simple enough to only run that kernel? and so, the whole OS is in that kernel?

also one last thing, what is GRUB? "a multibootloader", well, still a bootloader? so it must be on the first sector of the disk? and the problem will remain the same: how to get it in there? windows won't allow me to do this even using the cmd

Share this post


Link to post
Share on other sites
[quote name='Hassanbasil' timestamp='1303063500' post='4799535']
seems it's not the time to give up! following some tutorials, i managed to get my bootloader installed on a virtual system (virtualbox), hope i can go on from here, following your links

thanks again.
[/quote]
Be prepared to have to do a lot to gain very little:
To have a OS on a x86 platform that can execute application in usermode (search this on osdev.net or wikipedia if you don't know what it is) you need:
- Memory management (At least physical, but paged is better (better as in more common used) if you plan on having multiple programs run at once)
- OS-Calls (to get stuff on the screen, etc.)
- A ton of other stuff like a lot of tables (gdt, idt, irq's, etc.)

But then comes supporting hardware as you don't have any access to hard disk/optical disk/floppy disk, no ports like usb, Internet access through Ethernet or wifi and the list goes on.

Developing a OS is a very tiresome task and provides very little satisfaction for a lot of work.

Share this post


Link to post
Share on other sites
As assainator said, it will be a lot of work for very little benefit. Adding to what he said, to do any kind of graphics at all, you will need to switch to VGA or VESA mode, which is, in itself, a bit of work. Eg, if you want to use the BIOS functions to switch to graphics mode, you must be in 16bit code, while you will want 32bit mode for the rest of the code. Easy enough to switch between, but I found it to be a massive headache personally.
Another reason it is very hard to write an OS is it will be very difficult to debug or profile it. Chances are, if theres a crash, your machine (or rather, virtualbox) will hang or reboot.



Anyway, for the [color="#1C2837"][size="2"]gdt, idt and irq's I would recommend to just set up the most basic configuration (eg, copy and paste the code from [url="http://www.osdever.net/tutorials/view/brans-kernel-development-tutorial"]Brans tutorial[/url]) and just set up the timer and keyboard interrupts - and nothing else.[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]For memory management, I would use just physical memory and not bother setting up a virtual address space or paging. Similarly, I would keep it single-tasking, because setting up multitasking is a pain (plus multi threading is hard even with libraries and such available).[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]With all that out of the way, heres some links to get you going.[/size][/color]
[list][*][size="2"][color="#1C2837"]Brans tutorial, linked above, is a great intro covering the basics of setting up a C-based kernel.[/color][/size][*][size="2"][color="#1C2837"]The [url="http://www.brokenthorn.com/Resources/OSDevIndex.html"]BrokenThorn[/url] tutorials that PieGuy mentioned are quite detailed and should prove useful, but they use a lot of assembly, which I would recommend against if you want to actually get real work done (as opposed to doing it purely for the learning experience, in which case, go for it)[/color][/size][*][size="2"][color="#1C2837"][url="http://wiki.osdev.org/Main_Page"]OSDev.org Wiki[/url] contains a lot of information on a large range of topics[/color][/size][*][size="2"][color="#1C2837"][url="http://forum.osdev.org/"]OSDev.org Forums[/url] contains a lot of useful OS-development related discussions [/color][/size][*][size="2"][color="#1C2837"][url="http://www.osdever.net/tutorials/index"]OSDever.net[/url] has some good tutorials too[/color][/size][/list]
[size="2"][color="#1C2837"]You will want a copy of the [url="http://www.intel.com/products/processor/manuals/"]Intel manuals[/url] and/or the [url="http://developer.amd.com/documentation/guides/pages/default.aspx"]AMD manuals[/url] too.[/color][/size]
[color="#1C2837"] [/color]

Share this post


Link to post
Share on other sites
[quote]
doesn't really matter as long as i'm learning something new ;)
[/quote]
That is, in my opinion, the only attitude anybody should tackle an OS with, unless they happen to already be pretty experienced. In any case, good luck! and if you do manage to put something cool together, I would be very interested in hearing about your experiences.

Share this post


Link to post
Share on other sites
[quote name='dublindan' timestamp='1303246714' post='4800509']
[quote]
doesn't really matter as long as i'm learning something new ;)
[/quote]
That is, in my opinion, the only attitude anybody should tackle an OS with, unless they happen to already be pretty experienced. In any case, good luck! and if you do manage to put something cool together, I would be very interested in hearing about your experiences.


[/quote]

+1, It's really interesting to know how a computer works inside, and why. I to, would really like to hear from you if you put anything together.

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