Page 1 of 1

exeption handler

Posted: Sat Nov 19, 2011 1:35 pm
by sds2017
I have been working on a software exception handler for a while and cannot get it working and I keep on getting an error that says "interrupts.o: file not recognized: File format not recognized"(interrupts.o is a assembled version of my asm file interrupt.asm). I use nasm and I linked my c files and that one asm file.
Please help.

Re: exeption handler

Posted: Sat Nov 19, 2011 2:01 pm
by AJ
Hi,

Are you using the GCC Cross-Compiler detailed on the wiki? If so, your C files are being compiled in to 32 bit ELF object files and this is what ld also expects. You therefore need to tell your assembler to output in the same format. In nasm, you can use -f elf on the command line.

If you aren't using the GCC Cross-Compiler, you need to give more detail in the question (or start using the GCC Cross-Compiler!).

Cheers,
Adam

Edit: If you are using a 64 bit cross compiler, you would use -f elf64. For all supported nasm formats, use "nasm -hf" - basically, get NASM to output the same object file format as your compiler.

Re: exeption handler

Posted: Sat Nov 19, 2011 2:34 pm
by sds2017
Thanks for your reply but I'm compiling it into a flat binary and I'm not using a gcc cross compiler; I'm just using the standard gcc. How would I use the -f command to compile a flat binary?

Re: exeption handler

Posted: Sat Nov 19, 2011 3:06 pm
by Combuster
but I'm compiling it into a flat binary
No you are not. You are compiling to an object file, you are linking object files into a flat binary. You do not want to emit flat binaries from either gcc nor nasm because you would not be able to link them afterwards.


Oh and, you also earned a "learn to read" complaint for the following:
AJ's Linked page wrote:Creating a dedicated (cross-)compiler for your OS development work can save you many headaches. If ... your compiler and your assembler can't agree on binary formats
and
AJ wrote:For all supported nasm formats, use "nasm -hf"
Try to make it a habit to read through all relevant and less relevant material carefully because laziness won't get you anywhere and people here are rather keen on reminding you of that.