Developing os in Assembly

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.
dilipcs1992
Posts: 5
Joined: Sat Dec 03, 2011 8:58 am

Developing os in Assembly

Post by dilipcs1992 »

Hi everyone
i want to develope my own operating system. i have developed a basic operating system in c language using grub bootloader.
but i want to develope my whole operating system in low level assembly language using grub bootloader.
so is there any tutorial out there. or any source code. i need basic operating system printing "hello world" there after i can make on my own.thanks in advance
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Developing os in Assembly

Post by Love4Boobies »

If you already wrote a basic OS in C then you should be able to do it without any help. If you can't, you don't know assembly language yet---and that's obviously a requirement for wirting an OS in it. Not that writing an OS in assembly is recommended (due to portability and productivity reasons).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Developing os in Assembly

Post by Tosi »

Look at the assembly listing generated by your C compiler.
Or write it on your own, you should know assembly before setting out to make an OS.
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: Developing os in Assembly

Post by rdos »

Tosi wrote:Look at the assembly listing generated by your C compiler.
Not a good idea. C compilers usually generate lousy assembler code.
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: Developing os in Assembly

Post by Rusky »

20 years ago, maybe.
guyfawkes
Member
Member
Posts: 93
Joined: Mon Jul 18, 2011 9:47 am

Re: Developing os in Assembly

Post by guyfawkes »

Assembly coding is all about keeping full control, grub is used mostly by C coders who do not want to get there hands dirty.

Your much better using bootprog and write the simple code you need to set up A20 and go to pmode etc.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Developing os in Assembly

Post by OSwhatever »

dilipcs1992 wrote:Hi everyone
i want to develope my own operating system. i have developed a basic operating system in c language using grub bootloader.
but i want to develope my whole operating system in low level assembly language using grub bootloader.
so is there any tutorial out there. or any source code. i need basic operating system printing "hello world" there after i can make on my own.thanks in advance
Sorry, but I find your post a little bit contradictional. You have already written your own kernel in C using grub as boot loader. Now you want to make your own OS written in assembly.

I'm not going to question your reasons for doing this but if you have already created your own OS in C, you shouldn't really have any problems to get to the hello world part. Take your C code and make the same operations in the assembly language.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Developing os in Assembly

Post by Love4Boobies »

Rusky wrote:20 years ago, maybe.
Nah, even today. We just tell people they're good at it to trick them into avoiding a premature optimization. For the moment, they're very far from beating an experienced assembly programmer.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: Developing os in Assembly

Post by rdos »

guyfawkes wrote:Assembly coding is all about keeping full control, grub is used mostly by C coders who do not want to get there hands dirty.
:lol:

But grub is also useful when you want to multiboot your OS with other OSes. You can just "tear-down" the C-related stuff that grub expects to see in the exe-file. With assembly, it is easy to setup a new environment.

Then, of course, every serious project needs it's own boot-loader when running standalone.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Developing os in Assembly

Post by Combuster »

You can just "tear-down" the C-related stuff that grub expects to see in the exe-file.
Ohai, the liar is back. Grub does not require anything C in a kernel. It also lacks any and all support for PE specifics.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Developing os in Assembly

Post by egos »

My kernel is written in assembler. It has raw binary format. It can be booted directly by grub and by stage 1 boot loader.
If you have seen bad English in my words, tell me what's wrong, please.
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: Developing os in Assembly

Post by rdos »

Combuster wrote:
You can just "tear-down" the C-related stuff that grub expects to see in the exe-file.
Ohai, the liar is back. Grub does not require anything C in a kernel. It also lacks any and all support for PE specifics.
Yes, but it has support for ELF specifics, and that is related to C. Or at least these formats are not necesary when working in assembler-only.
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: Developing os in Assembly

Post by rdos »

egos wrote:My kernel is written in assembler. It has raw binary format. It can be booted directly by grub and by stage 1 boot loader.
Grub expects the binary to be in flat memory model, and also assume which selectors are mapped to the flat code/data segments. My main kernel is in a 16-bit segment, and thus cannot be loaded directly by grub. But a dummy 32-bit module can call the kernel and setup the correct register contents that the kernel expects to see. In fact, the kernel & device-driver & file-system image is loaded as a module instead, so the main "kernel" that grub sees is only a stub-loader. :mrgreen:

RDOS is loaded like this:

Code: Select all

rootnoverify (hd0,0)
kernel /rdos/kernel/boot/grubload.bin
modulenounzip /rdos/board/amdp6/rdos.bin
When I load without GRUB, I have a menu-interface (second stage) that scans the root directory of the boot-partition for files that end with .bin, and display them in a list. Typically, I have rdos.bin (standard booting) and safe.bin (safe fall-back booting) in the root directory. In that case, it is the second stage that does what grubload.bin typically do with grub + load the actual image into memory + setup protected mode.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Developing os in Assembly

Post by Solar »

rdos wrote:Or at least these formats are not necesary when working in assembler-only.
No, of course they are not. ELF was invented so that different toolchains could talk with each other, and that not everybody who wants to write an executable loader / linker / debugger / ... would have to re-start from square #1. No more, no less.
Every good solution is obvious once you've found it.
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: Developing os in Assembly

Post by rdos »

Solar wrote:
rdos wrote:Or at least these formats are not necesary when working in assembler-only.
No, of course they are not. ELF was invented so that different toolchains could talk with each other, and that not everybody who wants to write an executable loader / linker / debugger / ... would have to re-start from square #1. No more, no less.
AFAIK, ELF and PE was invented for applications, not for kernels. For applications, it makes sense to keep symbol-tables in the executable image, and to provide relocation information. It is questionable to have this in OS kernels. There is generally no reason to do run-time relocations in an OS kernel, and there is usually no "application" loader involved in loading and managing pagefaults in the OS-kernel.

IOW, the typical application formats (ELF and PE) does not seem quite adequate for an OS kernel.
Locked