Page 1 of 3

I am new and need help please.

Posted: Mon Jan 19, 2009 10:51 am
by casualasm
Hello all, i'm new at this forum.

I have two questions that I need to have some answers on from some of you guys. So I hope you can help me;

My first programming language I learned was assembly. I only learned bits of it, but enough to understand the basics and intermediate stuff. However, it was long ago (back when I was 15 years old), so I can hardly remember any of it now. I am however relearning the assembly language now.

I have always wanted to construct my own operative system for personal reasons. But I need help. So here are my questions:

1. I have been looking around and I don't know where to start. I have read tons of tutorials on how to begin, but they all are extremely different in many ways. Some tutorials state that you can use C/C++ to code your OS. This is not the case for me however, because my only language is assembly. I am most comfortable with the NASM assembler (Intel Syntax), so am I able to make my OS with that? If not, I have a book called "80x86 Assembly Language and Computer Architecture" that discusses the MASM assembler at great lengths, but to me MASM syntax looks very chaotic, so I would rather not use it... But if I have to do, then I will do it.

2. I understand that the first thing you need to make is a bootloader. You code the bootloader in assembly/C/C++ and compile it to a binary format, whereafter you convert the binary format to an image file so that the BIOS will load it up (once setting bootsectors up, or whatever it's called :)). Now my question to this is; It has to be possible to make the image for a CD and not a floppy drive like all the tutorials I have read covers. Is an image file like a .iso or is it something else?..

Okay, so theoretically let's put this up in a step-by-step situation so I can make sure i've understood it (through my own interpretations of tutorials and so forth):
1) I will use the assembly language to build everything essential to my OS, the assembler will be NASM (Netwide Assembler) and will be using Intel syntax (now i've actually put myself in doubt, as I am not sure this matters because NASM has it's own syntax, but whatever... Correct me if i'm wrong please).
2) Code a bootloader in assembly
3) Assemble the assembly code into an object file.
4) Image the object file
5) Put it on a floppy/CD
6) Run it on computer.

Is this right?

Thanks all.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:12 am
by JohnnyTheDon
I only learned bits of it
Know it like the back of your hand before you write an OS with it. You should also learn C, because many, many tutorials are written using it.
I am most comfortable with the NASM assembler (Intel Syntax), so am I able to make my OS with that?
Yes.
MASM syntax looks very chaotic, so I would rather not use it...
You actually can't. The license forbids OS development with MASM.
Is an image file like a .iso or is it something else?..
You compile a bootloader into a flat binary file. The extension is irrelevant, but .bin is preferred. You then copy this into your medium of choice. I recommend floppies or hard disks, because they're the simplest. That is what most of the tutorials assume you use.
1) I will use the assembly language to build everything essential to my OS, the assembler will be NASM (Netwide Assembler) and will be using Intel syntax (now i've actually put myself in doubt, as I am not sure this matters because NASM has it's own syntax, but whatever... Correct me if i'm wrong please).
2) Code a bootloader in assembly
3) Assemble the assembly code into an object file.
4) Image the object file
5) Put it on a floppy/CD
6) Run it on computer.
1. NASM uses Intel syntax for instructions, but AFAIK stuff like 'db', 'times', etc. and NASM specific. Be aware that making your OS entirely in assembly isn't going to be easy. If you want to make a fairly simple command line based OS you'll be OK, but if want to get very advanced you'll have issues.
2. I would actually do this first, and then work on a kernel.
3. Not an object file, a flat binary. The BIOS just loads the first 512 bytes of your code, it doesn't know what an object file is. If you want to put your kernel in a normal executable file, take a look at GRUB. It will load ELF files for you if you want to go that route.
4. If you are using a flat binary, and a flat HD or FD image, just copy your bootloader/kernel onto the beginning of the image. Alternatively, you can directly use your bootloader/kernel binary as your HD or FD image.
5 & 6. Use Bochs or Qemu or another emulator. Testing on RHW is much too slow for early development.

Good luck!

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:32 am
by casualasm
Thanks, that helped me alot.

Now, one last question; How will I know, that I know assembly like the back of my hand? Stupid question, but I feel it's pretty valid... But maybe wrong forum to ask such a thing :(

EDIT: And I will able to learn everything from reading through the NASM documentation, and then coding my own "little programs", right? (like a calculator, or a calender)

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:36 am
by xDDunce
[url="http://www.brokenthorn.com/Resources/OSDevIndex.html"]check this tutorial chain[/url] that was the second one i followed when i started, and it helped so much! it goes through making a bootloader in nasm to begin with and then move onto a C kernel. but you can do what you want after that really... the bootloader should keep you busy for a while though :lol:

and as for knowing asm off by heart: it will just flow out of your fingers and onto your computer screen. :lol:

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:37 am
by neon
You compile a bootloader into a flat binary file.
Only the boot strap code actually needs to be a flat binary. The main boot code ("OS Loader", or "Stage 2") can be written in a higher level language and does not need to be a flat binary.
Now, one last question; How will I know, that I know assembly like the back of my hand?
Usually when you can write assembly code without much problems, it becomes easier to work with.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:37 am
by casualasm
xDDunce wrote:[url="http://www.brokenthorn.com/Resources/OSDevIndex.html"]check this tutorial chain[/url] that was the second one i followed when i started, and it helped so much!
Oh man, that's sick dude... Thank you alot.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:39 am
by piranha
Cliche answer: When you're ready, you will know.

Real Answer: You're going to want to be able to use all of the basic instructions, and you need to be able to write programs that a functional in assembly. You need to understand a lot of it.

-JL

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:40 am
by casualasm
neon wrote:
You compile a bootloader into a flat binary file.
Only the boot strap code actually needs to be a flat binary. The main boot code ("OS Loader", or "Stage 2") can be written in a higher level language and does not need to be a flat binary.
One thing I don't understand is this; You start out by making a flat binary file (this is the bootloader). After that, you can build the kernel in, for example, C right? So i'd have to compile this C program on another computer and bring it as an .exe to the test computer. But how will it know what .exe is? Since that's a MS Windows extention (like Linux has it's own)... I'm pretty sure i've got it all wrong, but bear with me.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:48 am
by neon
casualasm wrote:But how will it know what .exe is?
Just have your bootloader dump the EXE file to some location in memory (either physical or the current virtual address space) and have your boot code parse its header info to execute it properly or to get additional information from the file. This applies to (I believe) any executable format.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:52 am
by Firestryke31
Truthfully, the format doesn't matter as long as you know how to load it. You can use PE (exe), ELF, flat binary, your own format that you invent, or whatever else you find. Typically, people go with flat binary in the early stages (bootloader and second stage) because it's just load it and jump/call, and move on to either PE or ELF (usually ELF around here) in later stages.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 11:54 am
by piranha
Plus, GRUB easily loads ELF (and I don 't know about others). That way you can skip the bootloader, but writing you own boot loader allows you to know more about the system, but skipping is easier. Thats your decision.

-JL

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 12:15 pm
by casualasm
piranha wrote:Plus, GRUB easily loads ELF (and I don 't know about others). That way you can skip the bootloader, but writing you own boot loader allows you to know more about the system, but skipping is easier. Thats your decision.

-JL
Well, i'd like to start from scratch... Skipping something would just ruin the whole experience.

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 12:26 pm
by Dex
Your best starting by using bootprog, this is a boot loader written in nasm, that can load a com or mz exe from a floppy.
I know you have not got a floppy, but you can use a floppy image to make a cd bootable.
http://alexfru.chat.ru/epm.html#bootprog
If you want to make your own bootloader than by studying bootprog it will help.
Your best to start off by making some bootable demo's, before moving on to your main OS.
See here for examples: http://forum.osdev.org/viewtopic.php?f=2&t=18763

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 8:35 pm
by LordMage
I actually slightly disagree with some of the previous posters. I also think you should learn a higher level language, which you can do without leaving ASM. I think like the OP that there is no point in skipping a stage of the development process. If I wanted something fast I would make a linux distro. I know the fun stuff is way way way after the bootloader but still I want to look at my OS and know that I programmed every bit of it.

I think that it is not as important to know ASM like the back of your hand as to be able to read it. I can't really program in ASM without trouble but I can look at it and step through the code. likewise I can look at some C or C++ code and break it down far enough to know the basic functions I want then I simple break out my Intel manuals to see what opcode will accomplish the task I need. I did have an excellent ASM reference though, it even covered sytem programming to a degree. I think it was called "The Art of Assembly", here is a link to a website that looks like it has a pdf version for learning 16-bit and 32-bit versions. The only bad part is the pdf's are broken down by chapters. You can also buy the books if you like the pdf's. There is also some information about programming in HLA or High Level Assembly, That is what I was talking about earlier with learning a higher level language for rapid development and not leaving ASM.

I personally think the BrokenThorn.com Tutorials are KING, they don't just through some code at you, infact most of what they have is informaional and it blows away the competition for gaining an understanding of the system and how things work. I wouldn't have any OS if I hadn't found them. I can't wait until the next one is posted. Even though I am moving past where they have left off.

anyway, I say enough ASM is enough I prefer C++ but really any compilable language will do as long as it isn't run-time compile like C#. If you want to do ASM only I would study DexOS, I think it is open-source and ASM, there is also MenuetOS, it's cool and fits on a floppy. you could look at thier code to see how certain things are done.

Well, I think I have talked enough. good luck with your OS

Re: I am new and need help please.

Posted: Mon Jan 19, 2009 8:45 pm
by neon
Sometimes you may find it easier to skip the boot stage and use an existing boot loader for now if your beginning requirements are unknown. If you do know if your system requires special boot time requirements, or your requirements require a custom boot loader for some reason, you can always develop one either before or even after the kernel program has been started.

It all depends on what you want the system to do, and the requirements needed for it. Pick an option and stick with it until you are further in your development time line...You can always go back to the boot stage again if you need to.

Oh, and good luck with your OS :)