OSDev.org https://forum.osdev.org/ |
|
Simple Bootloader to load bin https://forum.osdev.org/viewtopic.php?f=1&t=33203 |
Page 1 of 1 |
Author: | tomsk [ Sat Sep 22, 2018 2:58 pm ] |
Post subject: | Simple Bootloader to load bin |
I am new to things like OS dev, but I would like to ask you if there is any simple bootloader or tutorial how to load bin file (which contains custom OS). I read lot of tutorials about bootloaders, but mostly they end with Hello World and doesn't say how to load some bin file. I have kernel.bin which contains: kernel.asm: Code: bits 32 section .text align 4 dd 0x1BADB002 dd 0x00 dd - (0x1BADB002+0x00) global start extern kernel start: cli call kernel hlt and kernel.c: Code: kernel() { char* VideoMemory = (char*)0xb8000; VideoMemory[0] = 'M'; VideoMemory[2] = 'y'; VideoMemory[4] = ' '; VideoMemory[6] = 'O'; VideoMemory[8] = 'S'; } It uses grub as bootloader and kernel.bin is saved in /boot/ directory, but I would like to create custom bootloader which loads that kernel.bin I know that if I create custom bootloader I can use only first 510 bytes, because 511th and 512th byte contains magic number for booting. I know that I have to use: Code: times 510 - ($ - $$) db 0 db 55h db 0AAh But I don't know how to tell to that bootloader to load that kernel.bin |
Author: | BrightLight [ Sat Sep 22, 2018 3:21 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
I would strongly advice against writing your own boot loader when you have that little knowledge of the internal workings of operating systems and boot loaders. If you insist, however, there are quite a few things a boot loader has to do. I'll be assuming you are using BIOS and not UEFI.
Writing a functional boot loader from scratch is not as small as it may seem, especially since a lot of it is usually done in assembly language. Instead, get familiar with the basics and use GRUB for a while, and when you know enough about the internals of OSes and the PC, then you can write your own boot loader if you don't want to use GRUB. |
Author: | tomsk [ Sat Sep 22, 2018 3:28 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
Thanks and is possible to create bootloader which uses only that first stage (first 510 bytes) to load that kernel.bin or it have to be two-stage (larger) bootloader? |
Author: | BrightLight [ Sat Sep 22, 2018 3:40 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
tomsk wrote: Thanks and is possible to create bootloader which uses only that first stage (first 510 bytes) to load that kernel.bin or it have to be two-stage (larger) bootloader? Try it yourself. You'll easily see 510 bytes isn't enough to store file system-specific data in the beginning (BPB for FAT, other similar structures for other file systems), and leave space for loading file from disk, detecting memory, setting a display mode, parsing the kernel's executable format, etc. Although it's technically possible to load a file and set up protected mode and run it, there is hardly enough space to do anything a boot loader actually needs to do. |
Author: | akasei [ Sat Sep 22, 2018 3:50 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
@tomsk: Please use my bootloader: https://gitlab.com/akasei/Zero it's only 512 bytes long Note that it runs the kernel in 64-bit mode, but it's well documented so you'll know how to run in a 32 bit environment. |
Author: | tomsk [ Sat Sep 22, 2018 4:28 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
omarrx024 wrote: tomsk wrote: Thanks and is possible to create bootloader which uses only that first stage (first 510 bytes) to load that kernel.bin or it have to be two-stage (larger) bootloader? Try it yourself. You'll easily see 510 bytes isn't enough to store file system-specific data in the beginning (BPB for FAT, other similar structures for other file systems), and leave space for loading file from disk, detecting memory, setting a display mode, parsing the kernel's executable format, etc. Although it's technically possible to load a file and set up protected mode and run it, there is hardly enough space to do anything a boot loader actually needs to do. Thanks for info akasei wrote: @tomsk: Please use my bootloader: https://gitlab.com/akasei/Zero it's only 512 bytes long Note that it runs the kernel in 64-bit mode, but it's well documented so you'll know how to run in a 32 bit environment. Thanks I will try to learn from it |
Author: | glauxosdever [ Mon Sep 24, 2018 2:14 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
Hi, Since questions of similar nature as yours are somewhat common throughout the general osdev community, I made Bootloader FAQ. I'm all ears for suggestions. Regards, glauxosdever |
Author: | Antti [ Tue Sep 25, 2018 12:57 am ] |
Post subject: | Re: Simple Bootloader to load bin |
glauxosdever wrote: I'm all ears for suggestions You picked up on a topic that may end up being controversial. Although the FAQ is under your own username, new wiki pages should strive for neutrality. If you checked out the history of discussions about this topic on this forum, it would always have the same plot. Those who think that writing a bootloader (BIOS) is a bad idea use every opportunity to understate the importance of it, ridicule the museum hardware (e.g. floppies), or consider it to be a waste of time. Those how do think it is a good idea to write a bootloader have most probably done that and try their best to convince themselves that what they chose to do was not a bad decision. I did the latter so I am very biased when it comes to this topic. The best neutral argument for writing a bootloader (BIOS) that I ever can come up with is the genuine interest in the subject. Having fun is a subjective experience that cannot be disputed. With this in mind, I still think the discussion about the topic might be useful because both parties would learn something new that helps them go forward on the chosen road. Good that you started writing on the forum more actively! |
Author: | glauxosdever [ Tue Sep 25, 2018 4:30 am ] |
Post subject: | Re: Simple Bootloader to load bin |
Hi, Quote: You picked up on a topic that may end up being controversial. Although the FAQ is under your own username, new wiki pages should strive for neutrality. If you checked out the history of discussions about this topic on this forum, it would always have the same plot. Those who think that writing a bootloader (BIOS) is a bad idea use every opportunity to understate the importance of it, ridicule the museum hardware (e.g. floppies), or consider it to be a waste of time. Those how do think it is a good idea to write a bootloader have most probably done that and try their best to convince themselves that what they chose to do was not a bad decision. I did the latter so I am very biased when it comes to this topic. The best neutral argument for writing a bootloader (BIOS) that I ever can come up with is the genuine interest in the subject. Having fun is a subjective experience that cannot be disputed. Indeed, just about everything osdev-related we do may turn out to be controversial. Even paging has been a controversial topic sometimes. The intent of a wiki page, especially a FAQ, is to provide a weighted overview and let the reader decide for themselves. The problem is that, since I'm still the sole author of that page, its views are obviously biased in favour of mine (e.g. don't bother with floppies, don't do multiboot in your bootloader, start minimal and then see what the kernel wants/needs and implement it, etc). That's why I asked for suggestions.Although the relevant question (GRUB or custom bootloader?) hasn't been filled in yet, I'm in favour for doing a custom bootloader. I'll probably fill that section when I find some genuine arguments in favour of using GRUB (so it's weighted and not biased), unless I fill my part and someone else fills the other part. I think one suggestion I'd do is to use GRUB if the reader doesn't want to do better than GRUB (in the long run) or doesn't want to invest the necessary time to do better than GRUB (in the long run). Of course, that requires the reader to know about the shortcomings of GRUB, so maybe this suggestion could be improved. As for BIOS vs UEFI, I don't have any experience with UEFI yet, apart from doing a "Hello, world!", so I can't talk about that. Quote: With this in mind, I still think the discussion about the topic might be useful because both parties would learn something new that helps them go forward on the chosen road. While you are right, I don't think any experienced osdever that has made up his mind would read this FAQ, which is almost exclusively directed to osdevers who are just starting out and not sure how to do things or more experienced people who are willing to reconsider their stance, possibly by rewriting their OSes from scratch.Quote: Good that you started writing on the forum more actively! Thanks! I'm trying to be more active with both the forums/wiki and my projects, whenever I have the needed motivation. Currently, I'm doing a compiler for a custom programming language (I repeat, whenever I have motivation ), then I'll write the full OS in that language (hopefully). But maybe the ambitiousness of the project is putting me off? I don't really know. Some years ago, I was able to persist at writing a (bad quality) EHCI driver for three months; now I'm losing patience after only a couple of days. It's really crazy. I hope I can fix the bugs with myself before causing new bugs in my code. Regards, glauxosdever |
Author: | glauxosdever [ Tue Sep 25, 2018 2:22 pm ] |
Post subject: | Re: Simple Bootloader to load bin |
Hi, I added an (obviously biased) section about "GRUB vs custom bootloader". Feel free to suggest improvements and, why not, edit the page if you want. I don't mind that, despite having it still in my namespace. Regards, glauxosdever |
Author: | DiggDug [ Thu Oct 11, 2018 9:13 am ] |
Post subject: | Re: Simple Bootloader to load bin |
tomsk wrote: But I don't know how to tell to that bootloader to load that kernel.bin Greetings Tomsk. When I first started to learn how all this works, I started out with this website. http://www.brokenthorn.com/Resources/OSDevIndex.html It teaches how boot loaders work and shows example code step by step. It shows the two first stages of loading and even how to load a kernel from the 2nd stage. Another website I learned from is this one... http://www.osdever.net/bkerndev/Docs/title.htm And this shares pretty much the same thing, but from a different point of view. I love both of those sites. A gold mine of information. But read both with an open mind, because on the more modern computers, neither of those work any longer. But they are still good for learning purposes to understand how things work. ( NOTE : They do work in VirtualBox ) SIDE NOTE : Before you even begin to think about making an OS, you MUST.. and I can't stress this enough, you MUST know your compilers. I use YASM, and sometimes NASM depending on the situation, as my assembler. And I use a Cross-Compiler ( MinGW x64 ) on windows to compile my C code. I followed the directions here on how to make a Cross-Compiler : https://wiki.osdev.org/GCC_Cross-Compiler If you are on a windows machine, you only need Cygwin to make the cross compiler. After that, you can remove Cygwin. I never needed it after that. Hope this helps. Digg |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |