Bona Fide OS Developer
View unanswered posts | View active topics It is currently Mon Aug 19, 2019 3:00 am



Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
 GRUB says kernel.bin as unsupported executable 
Author Message

Joined: Tue Dec 29, 2009 8:37 pm
Posts: 7
Post GRUB says kernel.bin as unsupported executable
Hello all,

Good day!!

Recently i have been attracted by the OS development and this site is way too idealistic for a person to start writing an OS. Thanks to Bran's kernel Tutorial. After finishing i wanted to compile the kernel in linux instead of windows as explained by the author. First i got problem in linking with the linker script, gcc didnt take these so called leading underscores. so i had to use the compiler directive '-fleading-underscore' in gcc to get the flat binary image. Now here comeas my problem. I copied this kernel.bin file to a floppy similar to the way Bran has done it. I have to mention that my kernel.bin file's size is 1MB. But in the tutorial Bran's image has a kernel.bin with a size of only 12KB!! But it works perfectly whereas mine is not :(. GRUB said that the image is unsupported executable format. I used binary as output format just like in the tutorial. I made several other ways like converting it to ELF for i386 but still failed. I even tried to copy it to a bootable thumb drive where my linux is, and failed again. Seems GRUB configuration is correct. But the kernel binary is not.

Then i went for a search like what GRUB needs. Some where it mentioned about the error i got 'unsupported executable format'. In the gnu grub manual actually. It says that if the multiboot section is not proper and if the binary is not of linux/unix type compressed formats it would throw an error.

I am really confused now. Could you please let me know what i should do to get the kernel booting?

By the way, I use gcc version 4.4.1 and Nasm version 2.05.01 assembler.

My operating system is GNU/Linux with kernel 2.6.31.4 (Distribution - Ubuntu)

I use another system (celeron 2.4GHz 845 GL mobo) as the test bed. I use a floppy for booting.

My Makefile:
Code:
all:

   nasm -f aout -o start.o start.asm

   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o gdt.o gdt.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o idt.o idt.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o isrs.o isrs.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o irq.o irq.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o timer.o timer.c
   gcc -Wall -O -fstrength-reduce -fleading-underscore -fomit-frame-pointer -nostdlib -nodefaultlibs -finline-functions -nostdinc -fno-builtin -I./include -c -o kb.o kb.c

   ld -T link.ld -z max-page-size=0x1000 -o kernel.bin start.o main.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o
clean:
   rm *.o


Please help me. Thanks in advance.

-Sundar


Tue Dec 29, 2009 8:56 pm
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: GRUB says kernel.bin as unsupported executable
Hi Sundar,

I believe you are experiencing a common problem with object formats. I have had this same problem many times.

Try changing the format of the ASM object to COFF or ELF to see if either helps. If not you may need to build a compiler to target your system, ie. i586-elf-gcc.

Please read the following post on building a cross-compiler if the suggestion about changing object format doesn't work:

http://wiki.osdev.org/GCC_Cross-Compiler

_________________
Thank you for reading,

Kieran C G Foot


Wed Dec 30, 2009 6:44 am
Profile WWW
Post Re: GRUB says kernel.bin as unsupported executable
Hello Kieran,

Thanks for your fast reply. I'll go through the web page you provided once. Mean while, i have another question. If i use my own bootloader to load this binary image to memory would it work?
Ofcourse i have to raw write the kernel.bin binary using dd in linux along with the bootloader.

Please let me know if i can do that. Because i am planning to write a boot loader also.

Thanks again for your valuable information.

-Sundar


Wed Dec 30, 2009 10:47 am
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: GRUB says kernel.bin as unsupported executable
Yeah, you sure can :P

Using BIOS hdd/fdd IO, you can load sectors, just make sure you link and load to the same address ;)

_________________
Thank you for reading,

Kieran C G Foot


Wed Dec 30, 2009 11:04 am
Profile WWW

Joined: Tue Dec 29, 2009 8:37 pm
Posts: 7
Post Re: GRUB says kernel.bin as unsupported executable
Hello Kieran,

When you say link and load to the same address do you mean that i have to move it to a specific location in memory?
I guess there are some parts in the memory that i should not overwrite. Such as the 0000-3fff which is used by BIOS interrupts(i guess).
So if i use some other memory like starting from 0x7c00 would there be any problem?

please let me know if i am correct or wrong. If wrong, could you please explain any theory about that like which memory used for what purpose and which are free at boot time,etc or a link to some tutorial would suffice.

Thanks Kieran.

-Sundar


Wed Dec 30, 2009 8:48 pm
Profile

Joined: Tue Dec 29, 2009 8:37 pm
Posts: 7
Post Re: GRUB says kernel.bin as unsupported executable
Hello kieran,

I tried a very simple bootloader to load the sample kernel.bin to memory and execute from there.

I found out that for the kernel.bin to be loaded into memory, i need to know the number of 512 byte blocks. It comes to 2072 blocks or sectors.
So i did write a small bootloader that would transfer floppy contents from sector 1 to sector 255 (This was a test so i didnt try the whole 2072 sector copy).
Now that i have transferred 255 sectors, to memory location starting at 0x5000, i can jmp to that location and can start executing from there. I wrote this bootloader to sector 0 to the floppy and wrote 0x55 and 0xaa to 510 and 511 bytes in that sector 0. Then i used dd command to load the 2072 sectors of the kernel.bin file to floppy starting from sector 1 in the floppy(since sector 0 is for bootloader). I used a seek attribute to copy from sector 1 to sector 2072.

But damn me, it failed to boot. It was expected in the first try :D and again i tried few changes and failed multiple times. Again this was also expected :D

Now i have a pile of questions after this many failure.

1) How each sector is copied into memory. Will the BIOS take care of incrementing the address for each byte or word or double word that is being copied memory?
2) When we talk about memory, are we discussing about the RAM?
3) When we seek data from a particular address in memory, will we get 16bit(2 byte) data or 32bit(4 byte) data. I know that now i am in real mode only. So probably 16 bits per address location but still i am doubtful.
4) Do we need to increment the address by 1 position every time i copy a sector(assuming that the address is incremented for 1 sector by BIOS.
5) Now coming to kernel.bin file, the start.asm file has multiboot information for the grub, which obviously is not needed. Even if it is present, will the execution ignore them and start the kernel from global start routine?
6) And finally, i have to know about the no. of sectors present in a track and no. of heads present(should be 2 for each side) and how the floppy is organised.

It may be stupid to ask too many questions but i dont know how am i going to write a bootloader :(

Please help.

Thanks,
-Sundar


Wed Dec 30, 2009 11:47 pm
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: GRUB says kernel.bin as unsupported executable
Ill try and answer your questions Sundar:

In response to the post I missed, you can copy tour kernel allmost anywhere, unless its a system memory area, you can use the BIOS to find them, but they are pretty much standard. What I actually meant was to link your kernel to the correct address that you are going to load it at runtime. For example, If you link your code to 0x1234, but load to 0x1245 it will not function correctly, this is due to location offsets within the generated binary image.

On to the numbered questions :P

1) I cannot remember if the bios tace care of the sector value or not, sorry.
2) Yes, your binary kernel image will be copied from the FDD to a location in the RAM specified by you.
3) For data, in real mode its a maximum of 16bits, protected mode is 32bits.
4) Again, not sure off the top of my head.
5) If you do not use the multiboot information its ok, but you may want to pop the checksum value and the data pointer off the stack. NOTE: Grub leaves you in protected mode.
6) Ok, i think you can read this from the BIOS, but I think it is standard. There are plenty of tutorials around for loading sectors. Try fish them out and take a look.

Also, I find, rather then using somebody else's code, it's allways good just to use it as a guide and reaserch the topic yourself (ie. Loading sectors, BIOS FDD Access). This way, you know what is actually happening and how its happening.

Take a look on the net for BIOS Interrupts, you should find heaps of usefull documents that will set you going.

_________________
Thank you for reading,

Kieran C G Foot


Thu Dec 31, 2009 2:51 pm
Profile WWW

Joined: Tue Dec 29, 2009 8:37 pm
Posts: 7
Post Re: GRUB says kernel.bin as unsupported executable
Hello Kieran,

Thanks for your patience first of all :) you have answered to my stupid questions :)

Actually my plan is that once i compile and load the kernel image and see it is executing, then ill start playing with it here and there. Then, my following plan would be to implement drivers for full functional keyboard,etc. For that i need to have a very strong theory knowledge about BIOS, architecture, instructions and all that stuff.

In a single day we cant write a unix or linux :D

Can you recommend me some other BIOS related stuff in the web please?

I have this following ones. Its good in fact. But i dont know if there is some more out there having tremendous data about hardware and BIOS functions.

http://www.ctyme.com/intr/cat-003.htm
http://www.ctyme.com/intr/int.htm

Let me know if they are ok for a beginner.

Thanks for your fast replies :)

Regards,
-Sundar


Fri Jan 01, 2010 2:32 am
Profile
Site Admin

Joined: Sat Jul 25, 2009 7:44 am
Posts: 274
Location: United Kingdom
Post Re: GRUB says kernel.bin as unsupported executable
Hi Sundar, they are ok, but dint hold much information. Try to look fro Ralf Brown's Interrupt list, thar contains everything you need and more. Also try to look for a program called helppc, of which there is also a HTML version.

_________________
Thank you for reading,

Kieran C G Foot


Sun Jan 03, 2010 11:44 am
Profile WWW

Joined: Tue Dec 29, 2009 8:37 pm
Posts: 7
Post Re: GRUB says kernel.bin as unsupported executable
Hi Kieran,

Had a long break from this :) Had too much work load...

Now back to boot loader. I had a look into the copying part. The BIOS interrupt for transferring contents from floppy to memory.
I have a question. When i use dd command in linux to write the kernel image (the binary file alone. without GRUB) to a floppy, it takes care of writing all the sectors properly, considering the head number, track number and the number of sectors copied. So i think i need to know about the organization of data in a floppy to actually copy the data to memory right?

Can you shed some light over this please?

I have planned to write the assembly in nasm. (thinking about using gcc/gas also). But the syntax confuses me between nasm and gcc. I think i have to stick with atlease one. Can you also tell me is there advantage in nasm over gcc?

Thanks
-Sundar


Tue Jan 26, 2010 3:23 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.