Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: "Frank Cornelis" , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: DJGPP 2.01 Date: Fri, 5 Jun 1998 16:26:53 -0700 Message-ID: <19980605232649.AAB4158@ppp105.cartsys.com> Precedence: bulk At 09:52 6/5/1998 +0200, Frank Cornelis wrote: >Hi, >I've got a serious problem using DJGPP 2.01 >I'm working under Linux Slackware 3.2 >I want to make 16 bit plain binary files. >What I did: >In a file called "myasm.asm" >BITS 16 >GLOBAL myproc1 >GLOBAL myproc2 >myproc1 > ret >myproc2 > ret >---- >Compile this using >nasm -f elf myasm.asm If you want a DJGPP-linkable object file, you need -f coff. ELF is for Linux, but not for DJGPP. >Next make a file called "myasm.h" >void myproc1 (); >void myproc2 (); >---- >Next make a file called "main.c" >#include "myasm.h" >void main () { > myproc1 (); > myproc2 (); >} >---- >Compile this using >gcc -c -Wall main.c >Do: >ld -o main -Ttext 0x0000 -e main main.o myasm.o >objcopy -R .note -R .comment -S -O binary main main.bin >Now do: >ndisasm main.bin >Then you get something like: [snipped] >---- >You can see this is a 32-bit file, >because the CALLs are using 4 bytes for the >memory address and the CALLs points 2 bytes >besides the real myproc1 (at offset 20) and >myproc2 (at offset 21), because of the large >address. >I _need_ a plain 16 bit binary file for an >OS Loader. (I hate to do it all in pure asm) Well, GCC only officially targets a protected-mode 386. DJ Delorie has made a version that produces 16-bit code (suitable for an 8086). See www.delorie.com (I think it's under DJGPP). However, assembly is a quite appropriate language for an OS loader. Typically it needs to be extremely compact, and loading a kernel is not all that difficult of a task. (Unless you rewrite LILO...) >I made the dos-gcc, dos-ld, dos-objcopy using: >gcc-2.7.2.2.tar.gz & binutils-2.7.tar.gz on >Slackware 3.2 (normal configuration). >Making went OK. >I did: >dos-gcc -c -Wall main.c >All OK. >But when I do: >ld -o main -Ttext 0x0000 -e main main.o myasm.o >I get: >ld: warning: cannot find entry symbol main; defaulting to 0000000000000000 >main.o(.text+0x4): undefined reference to `___main' >main.o(.text+0x9): undefined reference to `_myproc1' >main.o(.text+0xe): undefined reference to `_myproc2' DJGPP's configuration prepends underscores to C-referenced symbols. Also, GCC calls a function called `__main' when it compiles `main', and that is assumed to be somewhere in the startup code. Since you don't have that, perhaps you should call your entry point something else. >---- >And when I do: >dos-ld -o main -Ttext 0x0000 -e main main.o myasm.o >I get: >main.o: file not recognized: File format not recognized >---- You need to decide whether you want to make this project with DJGPP tools or Linux tools. Currently you are mixing them (you compile with `gcc', but link with `dos-ld'), and that won't work. Since you are writing a primitive program that doesn't depend on any OS, it probably doesn't matter, and the native Linux tools will probably be less complicated to use, in which case you can ignore DJGPP altogether. (Yes, I know that's a horrible thing to say in this newsgroup ;-) Nate Eldredge nate AT cartsys DOT com