Making my kernel binary smaller
Making my kernel binary smaller
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.
Thanks in advance for your help.
Re:Making my kernel binary smaller
If you are using grub, you can actually bzip the kernel image and grub will have no problem loading it.
Re:Making my kernel binary smaller
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.
Re:Making my kernel binary smaller
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.
Re:Making my kernel binary smaller
Also you should try "-Os" option to gcc.. It tries to make the smallest code
Re:Making my kernel binary smaller
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.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.
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.
Re:Making my kernel binary smaller
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.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.
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.
Re:Making my kernel binary smaller
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.
Re:Making my kernel binary smaller
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.
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.
- Pype.Clicker
- 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
you'll love to read the manual page of "sync", and maybe as much the "Working with Disk Images" page of the FAQ.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.
Re:Making my kernel binary smaller
I use the floppy when I want to test my kernel on real hardware instead of bochs just to make sure it works.