OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:55 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: flat_boot: A single-stage bootloader with a menu and more
PostPosted: Sat Dec 19, 2020 2:24 pm 
Offline

Joined: Mon Oct 19, 2020 10:32 am
Posts: 14
Hello! I have been working on a bootloader easy to use, customizable(via a config file) and full of features, but white fitting on just 512 bytes. This is not my first iteration, last one used a filesystem more like USTAR, this one uses a fully-featured filesystem. Here you have a link with more info: https://github.com/segfaultdev/flat_boot

It was originally made for my own OS, flat_core, but I decided to make it public for everyone to use on their OSes. I would also love to see some feedback about it.

Some screenshots:
Image
Image


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sat Dec 19, 2020 2:28 pm 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
Not neccessary, but anyway an excellent piece! Nice :)


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sat Dec 19, 2020 3:15 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Your repo does not contain source nor a binary, so it is quite difficult to try it out. Are you planning to provide those? The flat-boot.c in your other repo does not have a menu nor a config parser, so I'm guessing this supposed to be a different flat-boot.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sat Dec 19, 2020 3:19 pm 
Offline

Joined: Mon Oct 19, 2020 10:32 am
Posts: 14
bzt wrote:
Your repo does not contain source nor a binary, so it is quite difficult to try it out.

How could I have forgotten it! #-o Now it is fixed.

bzt wrote:
The flat-boot.c in your other repo does not have a menu nor a config parser, so I'm guessing this supposed to be a different flat-boot.

You are right, that is an old version(that one was made in C and not in NASM, I later switched to the latter as code was too big).


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sat Dec 19, 2020 4:14 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
segfaultdev wrote:
How could I have forgotten it! #-o Now it is fixed.
Cool, thanks! :up: As for the loader, good job! It's amazing how much you could squeeze into 512 bytes!

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sat Dec 19, 2020 11:47 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
segfaultdev wrote:
fitting on just 512 bytes.

And without even using REP STOSW for your mem_set function? You just might have room for more features!

Unfortunately, FAT32 and exFAT reserve some space in the boot sector, so you would have even less room for code. You would probably have to split it across two sectors, and then it's not as much fun because you have more than 512 bytes to work with.


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sun Dec 20, 2020 5:43 am 
Offline

Joined: Mon Oct 19, 2020 10:32 am
Posts: 14
Octocontrabass wrote:
And without even using REP STOSW for your mem_set function? You just might have room for more features!

I will find more tricks like the one you mentioned to make it even smaller, and then I could be able to add more features like to continue booting with the next bootable drive or more customization, thanks.

Octocontrabass wrote:
Unfortunately, FAT32 and exFAT reserve some space in the boot sector, so you would have even less room for code. You would probably have to split it across two sectors, and then it's not as much fun because you have more than 512 bytes to work with.

...and that is why I did not do it myself :D, as I would want to keep it in the first sector but I don't think I could.


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sun Dec 20, 2020 7:47 am 
Offline

Joined: Mon Oct 19, 2020 10:32 am
Posts: 14
I now added a reboot option with F1, and made a release on GitHub.

I may also try to change the reboot key to F2 and add a help menu loaded from a help.txt file to F1, although it seems difficult having only 2 bytes left.


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Sun Dec 20, 2020 3:14 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
You might want to add a CLD instruction somewhere.


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Mon Dec 21, 2020 1:06 pm 
Offline

Joined: Mon Oct 19, 2020 10:32 am
Posts: 14
Octocontrabass wrote:
You might want to add a CLD instruction somewhere.

segfaultdev wrote:
I may also try to change the reboot key to F2 and add a help menu loaded from a help.txt file to F1, although it seems difficult having only 2 bytes left.


Well, I tried to make both changes by making it smaller to fit them, and I properly implemented the menu which shows the help.txt file on the screen, but now the problem is that my bootloader is 59 bytes too big, and I do not know how to make it smaller(I do not want to start using dirty tricks like writing into the null GDT entry, but it still would not fit). Is it even possible to do it?

This is the link to the new branch: https://github.com/segfaultdev/flat_boo ... evelopment


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Tue Dec 22, 2020 7:21 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
segfaultdev wrote:
Well, I tried to make both changes by making it smaller to fit them, and I properly implemented the menu which shows the help.txt file on the screen, but now the problem is that my bootloader is 59 bytes too big, and I do not know how to make it smaller(I do not want to start using dirty tricks like writing into the null GDT entry, but it still would not fit). Is it even possible to do it?
Oh yes, there's still place for lots of optimizations :-) Use the null GDT entry freely, that's common practice to put the GDT value there.

I've inlined some functions and rearranged things (which rendered some set register instructions unnecessary). With these, I've saved you 30 bytes (still 29 to go).

Notes: don't use pusha/popa that much in your internal functions. Instead try to figure out the registers and rely on their values. Your str_cmp could be improved too, not sure why you check 0xA after str_cmd_end label. Try to minimize direct memory addresses in instructions, as they need the most space.

Cheers,
bzt


Attachments:
File comment: Saved 30 bytes
flat_boot.s [5.28 KiB]
Downloaded 52 times
Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Tue Dec 22, 2020 10:37 am 
Offline

Joined: Mon Oct 19, 2020 10:32 am
Posts: 14
bzt wrote:
Oh yes, there's still place for lots of optimizations :-) Use the null GDT entry freely, that's common practice to put the GDT value there.
I've inlined some functions and rearranged things (which rendered some set register instructions unnecessary). With these, I've saved you 30 bytes (still 29 to go).

Thanks a lot for the help, I did not know that you could use the null GDT entry. I managed to fit it by making both the help function and some more functions smaller, which also made me learn about INT 10h AH=13h.
bzt wrote:
Notes: don't use pusha/popa that much in your internal functions. Instead try to figure out the registers and rely on their values. Your str_cmp could be improved too, not sure why you check 0xA after str_cmd_end label. Try to minimize direct memory addresses in instructions, as they need the most space.

Maybe some day I will fix those things, but not now :), as I would have to rewrite almost all of the code. And about str_cmp, you are right, that check is completely useless, cannot imagine what I was thinking of when I wrote it. Also, I learnt about cmpsb, and that made it quite smaller.

At the end I managed to add the help feature, just added it to have more features, as I cannot think of a great reason to use it. I will probably stop improving it for now and continue with my OS. Thanks to everyone who helped me.

Edit: I also made another release on GitHub if anyone wants to try it: https://github.com/segfaultdev/flat_boot.


Top
 Profile  
 
 Post subject: Re: flat_boot: A single-stage bootloader with a menu and mor
PostPosted: Tue Dec 22, 2020 12:08 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
Warning: dirty hack ahead. Once you've entered PMode and loaded the segment registers, you might could even overwrite other GDT entries, as the CPU caches them for faster access.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 32 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group