flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Operating System Kernel questions

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 06 Feb 2005, 00:13
Hello everyone.

Recently I have become interested in developing a small, basic Operating System. I have more than enough knowledge of Computer Systems, and I am a constant Linux user. However, OS creation is a whole new concept to me.

I would like to write a very basic kernel for my operating system; however, I can't seem to get GRUB to boot my kernel. Bear in mind that this is a new concept to me, and I am probably doing something very wrong!

When my system boots, I press 'c' for command line:

Code:
grub> root (fd0)
grub> kernel /mykern
Unkown Executable Format.
    


Any help that can be provided is appreciated. I would like to write the basic area of my kernel in assembly, but then I would like my kernel to call a C function after doing some basic INIT.

So, the question is - are there any documents out there that can help me? I have looked at MenuetOS, but unfortunately, I have no answer to my question yet.

Any help is greatly appreciated, and I hope I made my question clear enough - clarity has never been my strong point.

-Jeff
Post 06 Feb 2005, 00:13
View user's profile Send private message Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias 06 Feb 2005, 14:02
In addition to Menuet, a really good choice, in my opinion, another excellent alternative, with many useful attributes, particularly for self study, is Solos created by Bogdan:
http://www.hostileencounter.com/os/files/sol_os_src_2005_01_25.zip
Unfortunately, NEITHER os, good as they both are, offers an opportunity to boot from hard disk, for whatever reason, (and there are some reasonable explanations, just none that satisfy me) and therefore, much of the discussion concerns instead, booting from floppy, as though it was 1985.
You may wish to read through the posts of this OS section of flat assembler forum, as there are dozens of wizards on this forum, many of whom have addressed your question about booting from GRUB in previous postings. Hope you will submit your success, once you have attained your goal of booting your own kernel Smile
Post 06 Feb 2005, 14:02
View user's profile Send private message Reply with quote
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 06 Feb 2005, 18:10
Hello Tom.

For right now, I have decided to stick with the floppy disk method, and use an emulator. I decided that this would be good enough to get me basically going.

I did some reading, and it turns out that there are some specifications that have to be met by the kernel in order for GRUB to boot it. The kernel has to conform to the Multiboot standard as defined in the GRUB documentation.

Regards,
Jeff.
Post 06 Feb 2005, 18:10
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 06 Feb 2005, 18:18
MenuetOS can run from hard disk. Just visit its site.
Post 06 Feb 2005, 18:18
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 07 Feb 2005, 01:00
Why not use this "bootprog" you can get it here: http://alexfru.chat.ru/epm.html#bootprog
it lets you boot your OS as a com/exe or bin file, from a floppy or hdd, just by putting it on the disk and naming it the name in the bootloader.
eg: "MyKernel.exe" Cool.

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Feb 2005, 01:00
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 07 Feb 2005, 01:34
Quote:
Why not use this "bootprog" you can get it here: http://alexfru.chat.ru/epm.html#bootprog
it lets you boot your OS as a com/exe or bin file, from a floppy or hdd, just by putting it on the disk and naming it the name in the bootloader.


bootprog doesn't support filesystems other than FAT for one, and for a microkernel-based OS, it doesn't provide a way to load multiple modules at boot time. GRUB is more flexible in the long run anyway...
Post 07 Feb 2005, 01:34
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 07 Feb 2005, 02:29
When your are talking floppy, then there is only one file sys "fat12", you can bury your head in the sand, with other sys, if you want Shocked.
Also linux supports fat12 etc.

Do not make life, as a OS dev, any harder than it is, if i had a pound for every time i see this in a OS dev forum "I have a GRUB problem" or " BOCHS does not run my OS" i would be even richer than i am.

Remember "KISS"

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Feb 2005, 02:29
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 07 Feb 2005, 02:43
Quote:
When your are talking floppy, then there is only one file sys "fat12", you can bury your head in the sand, with other sys, if you want


You can use filesystems other than FAT12 on a floppy. I've used Oberon's filesystem, MinixFS, ext2, and others on floppies. In fact, FAT is a rather limited filesystem even on floppies.

Quote:
Do not make life, as a OS dev, any harder than it is, if i had a pound for every time i see this in a OS dev forum "I have a GRUB problem" or " BOCHS does not run my OS" i would be even richer than i am


It's not that hard to support GRUB. A few extra bytes at the start of a kernel, and you can use it easily. In fact, you could make a kernel that can be loaded from a raw floppy, bootprog, or GRUB fairly easily (I have done this). IMO, the flexibility that GRUB provides is worth a few extra minutes of typing.

Quote:
Remember "KISS"


I do -- it's my guiding rule in coding.
Post 07 Feb 2005, 02:43
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 07 Feb 2005, 03:15
By saying there is only one file sys for floppy's, this does not mean others can not be used, it means to use another file sys, other than fat12 is just making life difficult, as every OS worth its salt supports it.

And for those that need a little more, they can use "alexfru" other program "OS LOADER" read about it here: http://alexfru.chat.ru/los4d_manual.html

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Feb 2005, 03:15
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 07 Feb 2005, 03:37
os loader is still less useful to me than grub. Consider:

a) I don't use Windows or DOS on this box, and don't even have FAT support built into my Linux kernel (it's a module)
b) I boot my OSes using GRUB (including DOS/Windows on my other box thanks to the chainloading operation GRUB supports)
c) GRUB works with my filesystems of choice
d) COFF format as supported by OS LOADER is no better than using ELF (a cleaner format anyway) with GRUB. Or even a plain binary file with a couple extra header bytes...
e) OS Loader doesn't support net booting for diskless systems
Post 07 Feb 2005, 03:37
View user's profile Send private message Visit poster's website Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 07 Feb 2005, 10:21
agree not to agree..?
Post 07 Feb 2005, 10:21
View user's profile Send private message Reply with quote
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 07 Feb 2005, 12:48
Thanks for all the suggestions guys.

Recently I came accross this page: http://linuxgazette.net/issue77/krishnakumar.html

The most useful part of this page is the C code that can be used to create a bootable floppy disk - it is quite useful for on-the-fly creation. You can either use it to write to a floppy image, or you can use it to write to a real floppy.

Quote:

int main()
{
char boot_buf[512];
int floppy_desc, file_desc;


file_desc = open("./boot", O_RDONLY);
read(file_desc, boot_buf, 510);
close(file_desc);

boot_buf[510] = 0x55;
boot_buf[511] = 0xaa;

floppy_desc = open("/dev/fd0", O_RDWR);
lseek(floppy_desc, 0, SEEK_CUR);
write(floppy_desc, boot_buf, 512);
close(floppy_desc);
}


You can replace ./boot with the executable name of your kernel/loader/os, and you can replace /dev/fd0 with a floppy image name (e.g.; ./floppy.img). I have used this code both ways, and it works great either way. Compile with GCC - this code probably won't work on Windows systems. This code even adds the appropraite signatures to bytes 510 and 511.

-Jeff
Post 07 Feb 2005, 12:48
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 07 Feb 2005, 13:47
Other great tools that many os-devers use is:
Partcopy and Rawrite.
Post 07 Feb 2005, 13:47
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 07 Feb 2005, 17:36
bubach wrote:
agree not to agree..?
bubach, you would make a good diplomat Laughing.

_________________
\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.
Post 07 Feb 2005, 17:36
View user's profile Send private message Reply with quote
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 07 Feb 2005, 22:22
Hmm...I seem to have gotten a basic boot sector going on my floppy disk. I got it to write just a few short things to the screen; nothing much yet really, but its nice to know that something is going on. Wink

Now for the question -- where should my kernel take place? Should I have the small boot sector of my floppy disk call the kernel and then let it take over (I like the idea of this), or is there another way I should do this? I'm open to just about any ideas that you guys/gals can give me; I'd prefer some documentations, if anyone can provide some. Wink

By the way, I took a look at SolOS, gotta say it's pretty nice. It works much better in QEMU than MenuetOS does, and not to mention it's design fits my personallity more (basic and simple; im not the kind of person that likes fancy UI - that's why I don't use Windows Wink)

Thanks for all the previous help. Any further help is appreciated. Smile

PS: About the link I posted previously - there are 3 parts to it, so if you are interested, here are the three parts (might be more; search google if you want to find more).

Part I: http://linuxgazette.net/issue77/krishnakumar.html
Part II: http://linuxgazette.net/issue79/krishnakumar.html
Part III: http://linuxgazette.net/issue82/raghu.html

-Jeff
Post 07 Feb 2005, 22:22
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 08 Feb 2005, 05:03
The way i do it, is the bootloader which fits in the boot sector of the floppy, looks for my kernel on the floppy, if it finds it, it loads it into memory and gives control to the kernel, as there is a basic fat12 in the bootloader, it can find the kernel any wear on the floppy, as it looks for a file by a certain name.
My kernel starts in realmode set up all things need for pmode and then moves to pmode.
As i use a MZ exe format for my kernel, it is very easy to test and make changers to the kernel, you can just delete the kernel from windows or linux like any other file, and replace it with a new kernel.exe, also this way of booting lets me boot from Dos, if i want to.
I like to keep things Small and simple and this design let me do that.


Last edited by Dex4u on 06 Apr 2005, 15:47; edited 3 times in total
Post 08 Feb 2005, 05:03
View user's profile Send private message Reply with quote
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 08 Feb 2005, 12:43
Dex,

That's exactly what I'm wanting to do with my bootloader. Smile I suppose I'll have to search google for information on how to read floppy disks from assembly.

Cheers,
Jeff.
Post 08 Feb 2005, 12:43
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 08 Feb 2005, 17:34
@jeffwilson, Here is the nasm code (easy converted to fasm):
EDITED LINK DEAD
http://myfilebucket.com/u/ASHLEY40/BOOT12.ASM
It can load a exe/com or bin file, you can assemble it as a bin file and write it to a floppys boot sector with rawrite or use the code as a tut Smile.

Forum for DexOS: http://dex.7.forumer.com/


Last edited by Dex4u on 29 Mar 2005, 02:40; edited 3 times in total
Post 08 Feb 2005, 17:34
View user's profile Send private message Reply with quote
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 08 Feb 2005, 21:40
Thanks alot for the code; looks well commented, will have to take a good look through it. Smile

-Jeff
Post 08 Feb 2005, 21:40
View user's profile Send private message Reply with quote
jeffwilson



Joined: 06 Feb 2005
Posts: 10
jeffwilson 09 Feb 2005, 21:57
Alright, after looking at many bootloaders and examples, I think I get the basic idea of how to boot the kernel, but yet I don't. I mean, I see many examples, but none of them give enough guidence on what does what.

Are there any tutorials out there can explain the entire process step by step? Or am I just going to have to poke around until I find a method that works?

Another question I have is where the kernel will actually go? Should I put it right after the first sector and let it expand from there?

I thought about doing a command like this to copy the kernel:
dd if=kernel of=/dev/fd0 seek=512

Which will skip the first 512 bytes (sector 1), but I'm afraid that I do not know if this is the correct way to do it.

Could someone please clarify for me? I'm a bit fogged up right now, but I have been poking around, and have gotten this far, and am in no condition to quit my attempts at getting a basic system going. I am currently still in real mode; I figured the kernel should be the one to switch to protective mode, not my bootloader.

Any help is greatly, greatly appreciated. Smile

PS: Sorry if I have extended this thread beyond its limits; I have switched topics quite a bit throughout this topic...

TIA,
Jeff.
Post 09 Feb 2005, 21:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.