Page 1 of 1

[Problem] Problem with cygwin ld and ASM+C file/format

Posted: Wed Nov 23, 2011 7:12 am
by Threadcore
Hello

I am a bit confused about the build environment for creating an own OS. At the moment I use NASM and cygwin (gcc-4 and ld).

System: Widnows 7 x64
Target Own 32 bit OS

Files:

Code: Select all

build.bat = Compiles the files and call link.txt
link.txt = Links kernel32.asm and kernel.c
kernel32.asm = Assembler file
kernel.c = Dummy C file with a main 
Buildfile:

Code: Select all

nasmw -f aout -o kernel32.obj kernel32.asm
gcc-4 -ffreestanding -c -o ckernel.obj kernel.c
ld -T link.txt -o c32kernel.bin
Linkfile:

Code: Select all

OUTPUT_FORMAT("binary")
INPUT(kernel32.obj ckernel.obj)
ENTRY(start)
SECTIONS
{
  .text  0x10200 : {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(1);
  }
  .data  : {
    data = .; _data = .; __data = .;
    *(.data)
    . = ALIGN(1);
  }
  .bss  :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(1);
  }
  end = .; _end = .; __end = .;
}
Now I will link the assembler and a c file and create a binary, but I become an error:

Code: Select all

kernel32.obj: file not recognized: File format not recognized
When I change the aout to elf, I habe the problem with the "cannot perform PE operations". I read here and in the Internet (http://wiki.osdev.org/Cannot_perform_PE ... on-PE_file) about this error (sometimes they use an other format and have the PE error). I read something about, that obj is only for 16 bit code, is this really true ?

Best regards

Re: [Problem] Problem with cygwin ld and ASM+C file/format

Posted: Wed Nov 23, 2011 7:22 am
by Solar
Threadcore wrote:I read something about, that obj is only for 16 bit code, is this really true ?
No.

The Cygwin compiler generates Windows binaries, which is usually not what you want.

The link to the solution is actually in your question.

Re: [Problem] Problem with cygwin ld and ASM+C file/format

Posted: Wed Nov 23, 2011 7:22 am
by Nable
I read something about, that obj is only for 16 bit code, is this really true ?
No, afaik, .OBJ files contain COFF (or MS COFF), it's not limited to 16 bit code.

Re: [Problem] Problem with cygwin ld and ASM+C file/format

Posted: Wed Nov 23, 2011 7:26 am
by AJ
Locked before the flaming starts. As Solar said, the answer to the question is in the original post. Please read the wiki topic linked to in your post. As far as the object files are concerned, I suggest a healthy dose of applications programming and playing around with your toolchain as the next step.

Cheers,
Adam