NASM question

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
Candamir

NASM question

Post by Candamir »

I'm now switching from a flat binary kernel to an elf kernel, however, I changed my nasm commands from:

Code: Select all

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

Code: Select all

nasm -f aout -o start.o start.asm
And it assembles flawlessly. But when linking, it tells me the following:

Code: Select all

start.o: file not recognized: File format not recognized
And In my linker script, I use the following relevant code:

Code: Select all

OUTPUT_FORMAT_("elf32-i386")
I already checked nasm -hf, but didn't succeed... In the FAQ, the NASM all-in-one page didn't tell anything, either... Could you please help me?

Thanks

Thanks
Candamir

Re:NASM question

Post by Candamir »

Please forgive my ignorance and stupidity, I realized that I've been using another linker script :-[(I'm playing around with them). Obviously, ld accepted my elf output files from nasm, but now it doesn't accept the output format:

Code: Select all

c:/djgpp/bin/ld.exe: target elf32-i386 not found
upon this linker command:

Code: Select all

OUTPUT_FORMAT(elf32-i386)
Strange...

Well at least I learned my lesson now: Make all decision about your output format right from the beginning, and second, don't trust any code you don't understand line after line (the startup code still had much in common with the one from Bran's Kernel, and I didn't understand quite all the macros. I hope that at least my shame upon this will help me to "not code without using your keyboard" (you know, copy & paste :-[)... But just tell me what's wrong with my linker script...
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:NASM question

Post by Colonel Kernel »

If you're using Cygwin, you might need to create a cross-compiler. The version of gcc that comes with Cygwin targets Win32 (PE format) only. This may or may not be the problem you're having, but it's a common one, so I figured I'd throw it out there...

<edit>
Doh, nevermind... I see you're using djgpp. I think it produces 16-bit DOS executables only (someone correct me if I'm wrong)... In which case, I will give you the standard advice, which is to start using Cygwin (or Linux), build yourself a cross compiler, and stop reading the tutorials. Now. :)
</edit>
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
YeXo

Re:NASM question

Post by YeXo »

Djgpp can produce 32bit code fine. Actually, I'm also using djgpp myself. To let djgpp make elf executeables, you need the elf binarys. google for them.
paulbarker

Re:NASM question

Post by paulbarker »

My suggestion would be to use a Linux live-cd. I know it isn't everyones cup of tea, but makes using gcc/binutils/etc much easier because you're then running them on the platform they were created for. And using a livecd doesnt require installing anything!

Alternatively, use cygwin and watch out for 'PE operations on non-PE file' or whatever that error that I've seen 100 times is. You'll need a cross-compiler targeting ELF rather than Windows PE.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:NASM question

Post by Solar »

Funny how these keep popping up every other month or so. ;)

1) Re LiveCD - I discourage their use. One, they provide an environment that will be even more confusing to a Windows user than running Cygwin. Two, they quickly reach their limits in what hardware and protocols they support. (I have yet to find a LiveCD that provides wpa_supplicant and madwifi drivers, or more than 75Hz on my monitor.) Three, you have to reboot your system if you want to start development. Awkward. Four, the CD spinning up and down and apps needing ages to start is nothing for the impatient. Five, the GNU toolchain feels just as much at home in a Cygwin shell as on a Linux CD. (And has been designed for neither, as its initial release date of 1987 predates both by a good amount.)

2) Re DJGPP - I really don't understand the "pro's" of this one. Fork of an outdated version of GCC running in a wrapper around a wrapper, with "better support for Windows 2000 and XP" being "under development"... and you don't even get a full bash shell, Perl, make, debugger etc. etc. included as far as I understood it... I am not dissing anyone using DJGPP out of habit, but I really cannot understand why it is still recommended by anyone with Cygwin being readily available, well supported and with lots of useful tools.

Anyway, the FAQ is biased towards a GCC cross-compiler, not the least reason being because that makes you "even" with people developing under Linux, so everyone can reproduce each other's build process should any problems arise.

Use whatever makes you happy. I just had to say it. 8)
Every good solution is obvious once you've found it.
paulbarker

Re:NASM question

Post by paulbarker »

Thats actually a very good point (or set of points).

To be honest, the real question here is what environment any particular developer wants to use. You should be able to spend your time coding rather than fighting with the environment.

Alternatively, just compile to any format you like and use a multiboot loader like GRUB which can read any format as long as you give it a good multiboot header. I've never tried it myself, but it should work.
Kemp

Re:NASM question

Post by Kemp »

Candamir wrote: I'm now switching from a flat binary kernel to an elf kernel, however, I changed my nasm commands from:

Code: Select all

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

Code: Select all

nasm -f aout -o start.o start.asm
Did I miss the part where you changed it? ;)
Candamir

Re:NASM question

Post by Candamir »

Well, obviously I used nasm -f elf, you didn't miss the change;). But anyway, I'm now building my cross-compiler (used windows tools before, now switching to cygwin, along with a rewrite-from-scratch of my kernel, quite a few changes, huh?), but when following exactly the instructions from the FAQ, I reached make all install, and then it returned with an error:

Code: Select all

...
checking for C compiler default output file name... a.exe
checking whether C compiler works... make.exe *** [configure-libiberty] Error 1
I suppose this means that the C compiler is not working... but I don't know how to fix it... Does anyone do know? I installed cygwin just a few days ago, and selected all packages for download.

Thanks

Edit: i downloaded binutils-2.16.1 and gcc-core-4.0.2, the latest ones listed in the square...
Edit: I did google for this and I also tried site:mega-tokyo.com, and nothing intelligent at the first try (whole web) and nothing at the second (mt)

Edit: I tried typing only make and I would then afterwards type make install, and when I typed make several times, every time the build failed, the process seemed to advance somehow... every time I executed the command, another part of the task was done... but anyway, the error was always couldn't make stderr distinct from stoudt (after a time, the above mentioned 'solution' didn't work anymore) And BTW, what seems strange to me is that when I run the configure script, it also checks for the c compiler to work, and there's no problem...
Candamir

Re:NASM question

Post by Candamir »

Ok, I've downloaded binutils 2.15 and also tried it, and tried to run it. The error of configure-libiberty didn't appear, but the couldn't tell stderr blabla wouldn't stop popping up. It also came at the beginning. I'm following the exact specifications of the FAQ and still nothing... I did quite a lot of googling, but the only thing I can find is some strange posts about some people accessing bash trough Win2k telnet ???... Does anyone know a solution for this? Because I just _can't_ install Linux on any of my machines... well, my machine... (not allowed to...)the other ones at my place don't belong to me... I'm thinking of using LiveCDs, but I don't like that concept...

Ok, sorry for moaning around, but I would really appreciate your help!
rootel77

Re:NASM question

Post by rootel77 »

hi,

there is no need for a cross compiler in cygwin to produce an elf executable.

actually i use the following commands in the makefile

Code: Select all

ld -T link.lds $(OBJS) -o kernel.tmp
objcopy -O elf32-i386 kernel.tmp kernel.elf
$(RM) kernel.tmp
the generated elf work fine with the grub bootloader. (the only problem i get is when debugging with gdb, it seems my objcopy executable can't convert the debugging info for variables in my c++ code)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:NASM question

Post by Solar »

@ Candamir:

The compiler you are building using the Cross-Compiler HOWTO in the FAQ is step one towards a complete toolchain, as is described on that same page. It is sufficient to produce a kernel binary, but - for lack of a C library / runtime for your target OS - it is not able to produce a standalone executable.

Thus, auxiliary tools like autoconf will fail.
rootel77 wrote: there is no need for a cross compiler in cygwin to produce an elf executable.
No, but it makes many things easier and answered dozens of repetitive questions in the past, which is why it is recommended practice. Besides, it is the first step towards a native toolchain (again, as described on that FAQ page), which is what you are aiming for unless you want to be stuck with cross-compiling forever.
Every good solution is obvious once you've found it.
Post Reply