Making my kernel binary smaller

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.
Post Reply
iammisc

Making my kernel binary smaller

Post by iammisc »

When I was compiling my kernel I realized that it was already 8kb and if it got any bigger it would be hard to fit on a floppy disk. Using the -fwritable-strings option made it smaller and i was wondering whether there are any other options that I can pass to NASM or gcc that would make it smaller. Or are there any coding tips.

Thanks in advance for your help.
DruG5t0r3

Re:Making my kernel binary smaller

Post by DruG5t0r3 »

If you are using grub, you can actually bzip the kernel image and grub will have no problem loading it.
Warrior

Re:Making my kernel binary smaller

Post by Warrior »

I'd also consider with the size of your kernel growing, perhaps it's time to move on to a CDRom instead of a floppy disk.
iammisc

Re:Making my kernel binary smaller

Post by iammisc »

The linux computer I am developing on does not have a cd writer. Also, how would I use grub iso images with a emulator such as bochs.
giszo

Re:Making my kernel binary smaller

Post by giszo »

Also you should try "-Os" option to gcc.. It tries to make the smallest code ;)
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:Making my kernel binary smaller

Post by nick8325 »

iammisc wrote: When I was compiling my kernel I realized that it was already 8kb and if it got any bigger it would be hard to fit on a floppy disk. Using the -fwritable-strings option made it smaller and i was wondering whether there are any other options that I can pass to NASM or gcc that would make it smaller. Or are there any coding tips.

Thanks in advance for your help.
Actually, I wouldn't worry about this. What happens is that ld will put some sections on separate pages. For example, it might give 4KB for code and 4KB for data.

If this happens, even if you only have a few bytes of code and data, the kernel will be 8KB. But it won't grow any bigger until you have more than 4KB of code or data.

You can use a linker script to pack the data more tightly and put everything on the same page, but it's not a good idea - if you have code and data on the same cache line, your code will run very slowly, because whenever you write some data, the processor will think you have changed some code and will read in that whole cache line again.

So: don't worry about it unless your kernel carries on growing very quickly.
Cjmovie

Re:Making my kernel binary smaller

Post by Cjmovie »

iammisc wrote: When I was compiling my kernel I realized that it was already 8kb and if it got any bigger it would be hard to fit on a floppy disk. Using the -fwritable-strings option made it smaller and i was wondering whether there are any other options that I can pass to NASM or gcc that would make it smaller. Or are there any coding tips.

Thanks in advance for your help.
How would it be hard to fit on a floppy? A floppy can hold 1.44mb of data. Even considering the worst FAT trouble, you'd still get at least 1mb out of it. And 1mb = 1024KB. You've got a while to go before you reach that limit.

Or is there some other constraint (boot loader?)? Can it only load into real mode (1stMB)? If so you might consider putting the boot loader in Unreal Mode to get more space.
iammisc

Re:Making my kernel binary smaller

Post by iammisc »

Yeah i know a grub floppy can hold 1Mb of data but when I copy any file bigger than 1 Mb to the floppy umount just hangs and doesn't do anything it just keeps making that floppy reading sound for a long time.
AR

Re:Making my kernel binary smaller

Post by AR »

Linux has extensive disk caching, it doesn't actually write anything to the disk at all until you umount, writing to a floppy is extremely slow and could take several minutes.

And why are you trying to write that much stuff to the disk anyway, you shouldn't really need anything other than GRUB and the kernel image which shouldn't be more than a few hundred KB or so altogether.

Another question, if you're using Bochs then why do you need to use a physical floppy at all? On Linux you have the advantage of the loopback device for creating disk images without needing physical floppies.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Making my kernel binary smaller

Post by Pype.Clicker »

iammisc wrote: Yeah i know a grub floppy can hold 1Mb of data but when I copy any file bigger than 1 Mb to the floppy umount just hangs and doesn't do anything it just keeps making that floppy reading sound for a long time.
you'll love to read the manual page of "sync", and maybe as much the "Working with Disk Images" page of the FAQ.
iammisc

Re:Making my kernel binary smaller

Post by iammisc »

I use the floppy when I want to test my kernel on real hardware instead of bochs just to make sure it works.
Post Reply