My Own OS!

Pages: 12
Congratulations newbieg, great acheivment!

I think I still have my OS source code somewhere if you would like to use it? I got it set up in 32bit protected mode, FAT16, IVT and IDT were set up. The bootloader loads a file called "Kernel.bin" (Written in flat C), loads it into code space and executes it. Unfortunately it is CLI (Was in the middle of writing a keyboard driver before IRL took over my time). I couldn't be bothered putting gfx card into graphics mode seemed too much effort to go forward with for something that was only a hobby.

Really fun project to choose, not only does it teach you to code at a lower level, but you can learn much from how the hardware cpmmunicates to each other.


Anyway, well done and I hope you keep advancing it!

Small Edit - It's not an OS until it's running something :P I liked to call mine "Bootable code" because that's all it were without a loop to be able to load and exceute programs in the .TSS task segment data ring.

Small Edit 2 - I see you have been having problems following the OS dev site. I also encountered what seemed to be missing notes or abruptly changing on to another topic. In all honesty I don't think the website is supposed to provide a "from scratch" method. I had to find a lot of information else where such as the Intel programming manuals if IIRC and other websites.
Last edited on
Thanks Megatron 0,
I'm always open to a little light Summer reading.

Title of the Intel manuals that I downloaded;
1) "Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1: Basic Architecture"
2) "Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2 (2A, 2B, 2C & 2D): Instruction Set Reference, A-Z"

[Edit: the above are an incomplete set, find the full compilation file under https://software.intel.com/en-us/node/699529#combined]

Seriously, I'm a bit intimidated by those files.

An interesting note between the OSDev version and Blundell's (I haven't gotten into his 32 bit version yet);
The real-mode code Blundell provides seems to run at full tilt, eating up 100% of one of my cores.
The "Meaty Skeleton" version only appears to sip at it when running on qemu. (Indicating that we are in a NOP state?)

[Edit:
It's because the hlt statement in their boot.s file. They even go a couple steps further in that even though interupts are turned off, if we were to get interupts to work again, it just makes us jump to just above the hlt statement. I was hoping it was inside of the C code... ]
Last edited on
I forgot that they no longer ship the actual books for Intel or AMD. I never bothered getting the AMD ones, but I have the Intel set. They are collecting dust on the bottom shelf of my bookshelf.
@newbieg

Just wondering if you have heard of MINIX (Minimal Unix) . You should be able to get the code for it. Another one which may be of interest is Arch Linux, AFAIK when it is installed there is only the shell, the user decides what to install from there on.

https://en.wikipedia.org/wiki/MINIX
https://en.wikipedia.org/wiki/Arch_Linux

Code should be available for all the Linux OS's, so if you were really keen you could experiment with it.

Good Luck !!
Thanks for reminding me about that one, I did mention Tanenbaum's books (he's the one who started and maintains Minix), I think one of them even includes source code for a version of Minix3... Anyhow, I hadn't gotten around to downloading the source to Minix3 yet, doing so now.

For the source code of Minix3;
https://github.com/Stichting-MINIX-Research-Foundation/minix
I'll report the final download size of the zipped folder once it finishes downloading on my side.
EDIT: 146MB (I think this includes build tools, the final-built OS may be much smaller)
I'm not 100% sure on how large is the actual size of the code, I'm seeing claims that it is built with 6000 lines of code (pretty small for an OS that's got networking and other drivers). I don't know if this is a reference to the entire build or to just the kernel itself... I know his goal is stability and readability over optimization since it's meant as a learning tool for colleges which suits me just fine.

I don't intend to build Minix3 tonight because It's late and I just finished my Calc3 final. I'm too zapped right now.
I'm going to try to finish Blundell's book in the next few days, and take brief excursions into the code behind Minix3 in that time.

Edit #3-ish: Sigh. Blundell's book ends half way through chapter 6 just before he gets into actually developing a driver for the keyboard and for the hard-disk. I do appreciate his book for the crash-course in Assembly, and for the list of tools that he brings up in a well-thought-out manner. I hope he'll finish his book some day.
Last edited on
@newbieg

My source files are on a different machine to my current one so it will take me a day when I'm not busy to get my other one out of storage and upload them. I don't want to give you a zip file so I may give you a bunch of links to pastebin while trying to order the files as I have them in the directories. I think I was using OracleVM to test the code. For the FAT16 to work I think I had to create a floppy image on Windows because Linux wasn't doing it correctly for me. For Linux I ended up writing a custom floppy image maker in C++ before switching over to Windows. However having to write code to an image on a sector by sector basis meant I always had to keep track of where to load code from (Unlike FAT where you can search by name). This also lead me to "pad out" code that wasn't a multiple of 512 with 0's, loosing space.

I wish I could help you more but I am no professional. Hopefully the code I gathered from the internet will shed some light on the topic.

I will post here again when I get to my old machine, good luck!
@: megatron - I'm not sure how you'd prefer to share the files, but yes, I'd like to see them. I'd tend towards github myself, that way you could specify a license and all... (A good idea since many of the licenses protect you the coder in case someone blames it for burning out their hard drive or something)

I'm currently building Minix. It's been running the releasetools/x86_hdimage.sh script for about 40 minutes now. I'm going to step away from the computer and just let it do its thing.
http://wiki.minix3.org/doku.php?id=developersguide:crosscompiling

Edit: I'm regretting not planning ahead. If I had to rebuild this from scratch I would run it as;
$ time ./releasetools/x86_hdimage.sh; mplayer LoudMusicFile.mp3
As it is I have no indication when the script is done building, and can't give you guys an accurate time it took to do so. The instruction set above does say that reruning this script will take less time in future because it won't have to build the entire toolchain from scratch.

Getting a GUI running for Minix3 (just because it's possible); http://pclosmag.com/html/issues/201112/page15.html

EDIT: I finished the build just a few minutes ago. So, in all I would say to expect about 5 hours of build-time for your first run. I went ahead and tested on qemu, and am currently dd'ing the image to a usb stick. -- Failed, booting from USB is no longer supported in Minix3. In the same folder as the above build script you'd find a usb and a cd buildscript. I tried both (taking about 10-15 min each) and only the cd one was bootable on my computer.
Last edited on
I've talked to Blundell and he said he plans to finish the book when he finds the time for it. His exact quote from me asking about his book ending partially through Chapter 6:
I'm currently working on finishing this stuff off - whenever I get the time - but hopefully it will not be too much longer now.
No way, that's great.
His book in it's current state is at the top of my recommended reading list if anyone wants to get started (Especially if they're like me and don't have a previous background in assembly).
Last edited on
Here's nice instructions for calling a function that's defined in assembly from inside a C++ program.
http://lavernasbrute.blogspot.com/2010/02/calling-assembly-functions-in-c.html
Technically you're prototyping a function as C code, then using a linker to insert the assembly definition...
Useful if you want to move as much code to C/C++ as possible...

I do have a noob question about using extern "C". As far as I understand name-mangling: it's to do with C not having overloaded functions. So, in the example from the link, would I run into errors if I tried to write an "add" function with multiple arguments, or that took a vector as input?
Last edited on
As far as I understand name-mangling: it's to do with C not having overloaded functions. So, in the example from the link, would I run into errors if I tried to write an "add" function with multiple arguments, or that took a vector as input?


The function in the example from the link already takes multiple arguments (two of them). The C++ file that declares extern "C" int add(int a, int b); expects to link with a file that defines add (as it does in the link). A C++ file that declares int add(int a, int b); expects to link with a file that defines _Z3addii (assuming non-Windows)

Also keep in mind the page is using 32-bit assembly. If you on 64 bits (as you should be in 2017), the stack is not used here: for a non-Windows 64-bit intel, that function would be
1
2
3
4
add:
        add  edi, esi
        mov  eax, edi
        ret  

for Windows, it would be
1
2
3
4
add:
        add  ecx, edx
        mov  eax, ecx
        ret  
@newbieg Seeing you give updates on here made me wonder, have you considered making a WordPress blog to chronicle your progress? Just a thought as you can go in depth without a limit in terms of characters as you do on this site of 8192 characters and you can leave it as a guide for what to do and not to do for future OS dev enthusiasts.
@: Cubbi - Thank you for the run-down on the code. I phrased the question poorly, I should have said "more arguments" since I was thinking of examples of overloading the function name

@: BHX - That might be fun (and might be the most that comes out of this project at it's end), but I think right now I'd really like to keep things open to a back-and-forth. (Plus it's becoming increasingly clear just how amateur I am right now)

Next Book;
"MMURTL v1.0 pdf" (pronounced like the name Myrtle). Originally published in 1995, It offers both OS theory and example code for how he wrote his OS called MMURTL.
(I'm pretty sure it was made available free online by the author himself though the copy license in the book itself doesn't exactly specify this... I still think it's OK to download.)
Last edited on
Just posting a link to the AMD developer guides/manuals list
http://developer.amd.com/resources/developer-guides-manuals/

Edit:
A tutorial for developing an OS in 64 bits, I haven't gone through it in any detail, but something to go back to.
http://ethv.net/workshops/osdev/notes/notes-0

While the above 64bit tutorial has a section about how to access fat32 file systems, that is not and should not be the end-goal (though it absolutely should be supported/implemented because it is so common on other systems). My wish-list includes supporting ext4 as the default file system. (That's of course a long term goal among many); https://www.ibm.com/developerworks/library/l-anatomy-ext4/

I'm still reading through the MMURTLE pdf, it helps explain what-where-and-why of things.
Last edited on
I've found couple of hobby OS's out there to look through for example code. Quite a few users in the OSDEV forums ( http://forum.osdev.org ) supply links to their OS source code in their signature section for posts. Of those, look for projects with licenses that allow for re-use.

http://forum.osdev.org/viewtopic.php?f=1&t=12087&start=2985 - this active OSDEV thread is where people show off pictures of how far along they are. Found a lot of open sourced projects there.

Last edited on
Topic archived. No new replies allowed.
Pages: 12