[ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs

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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by gerryg400 »

Kortath, I made 2 changes to your linker script and built your kernel on Win 7-64 using Cygwin and the GCC 4.81 compiler I built earlier.

Code: Select all

OUTPUT_FORMAT("binary")

SECTIONS
{
  .text 0x100000 : ALIGN (0x1000)
  {
      code = .;
      _code = .;
      __code = .;
      *(.text)
      *(.rodata*)
  }
  .data : ALIGN (0x1000)
  {
      data = .;
      _data = .;
      __data = .;
     *(.data)
  }
  .bss : ALIGN (0x1000)
  {
     bss = .;
     _bss = .;
     __bss = .;
     *(COMMON)
     *(.bss)
  }
  end = .;
  _end = .;
  __end = .;

 /DISCARD/ : { *(.comment .note .eh_frame) }
}
You can see I added a discard for the .eh_frame .note and .comment sections. You don't need those yet.

Also I changed the way that the ALIGN is specified for the sections. The way I have done it means that if a section does not exist, no alignment will be added for it.

The result was a 466 byte binary.
If a trainstation is where trains stop, what is a workstation ?
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

gerryg400 wrote:Kortath, I made 2 changes to your linker script and built your kernel on Win 7-64 using Cygwin and the GCC 4.81 compiler I built earlier.

Code: Select all

OUTPUT_FORMAT("binary")

SECTIONS
{
  .text 0x100000 : ALIGN (0x1000)
  {
      code = .;
      _code = .;
      __code = .;
      *(.text)
      *(.rodata*)
  }
  .data : ALIGN (0x1000)
  {
      data = .;
      _data = .;
      __data = .;
     *(.data)
  }
  .bss : ALIGN (0x1000)
  {
     bss = .;
     _bss = .;
     __bss = .;
     *(COMMON)
     *(.bss)
  }
  end = .;
  _end = .;
  __end = .;

 /DISCARD/ : { *(.comment .note .eh_frame) }
}
You can see I added a discard for the .eh_frame .note and .comment sections. You don't need those yet.

Also I changed the way that the ALIGN is specified for the sections. The way I have done it means that if a section does not exist, no alignment will be added for it.

The result was a 466 byte binary.

0x1000 is the same thing as 4096. Hmm I'll give this a try and see what comes of it. I'll let you know the results once I'm done. Thanks for help.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by gerryg400 »

It's not that I changed 4096 to 0x1000, it's where the ALIGN is placed that's different. Good luck with it.
If a trainstation is where trains stop, what is a workstation ?
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

gerryg400 wrote:It's not that I changed 4096 to 0x1000, it's where the ALIGN is placed that's different. Good luck with it.

Thanks man. Are you sure I should be using i386-elf ? The OSDev GCC Cross Compiler Tutorial says to use i586-elf. Which do you recommend I use ?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by gerryg400 »

I didn't notice that I did that. i586 is probably more sensible.
If a trainstation is where trains stop, what is a workstation ?
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by sortie »

The cross-compiler tutorial (I wrote the latest revision of it) merely suggests i586-elf. It should cover pretty much all relevant hardware in use today. It would probably be better to use i686 if you don't care about i586 hardware, which is kinda reasonable these days. Though, for personal use with a modern computer, I doubt it really matters whether you use i586 or i686 except it probably enables the compiler to use some extra instructions and optimizes a bit differently.

Also note, to run the cross-compiler, run i686-elf-gcc or i586-elf-gcc - not just 'gcc'. (In a previous post you seemed to say you just ran 'gcc' which isn't your cross-compiler, disregard this if I am mistaken).
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

sortie wrote:Also note, to run the cross-compiler, run i686-elf-gcc or i586-elf-gcc - not just 'gcc'. (In a previous post you seemed to say you just ran 'gcc' which isn't your cross-compiler, disregard this if I am mistaken).

Thanks for the info on the i686.

I ran the GCC version your mentioning. I get what you mean by it, and yes that is what I tried. In fact it was in one of my batch file tests. But I also used the regular GCC that was in the cross compiler bin folder. So when I posted the batch file to this thread, that was that particular GCC version. I'll continue to use the one your mentioning from now on. Thanks for the tip.

@ gerryg400

I finally cleaned up that script of yours because it doesn't work. Not sure how you did it when I'm using your same script. Either way, I am to the part of this command : make -j 4 all

I get this error : Makefile:841: recipe for target `all' failed

How did you get around this ? How could you have compiled this with your script with all these errors ? You said you compiled it and it took only 8 minutes. So I am curious how you did it.

This is your script cleaned up :

Code: Select all

#!/bin/sh
export BUILDROOT=$(PWD)/..
export PREFIX=$BUILDROOT/cross-tools/
export TARGET=i586-elf
tar -jxf binutils-2.23.1.tar.bz2
mkdir binutils-build-2.23.1
cd binutils-build-2.23.1
../binutils-2.23.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls
make -j 4 all
make install
cd ..
tar -jxf gcc-4.8.1.tar.bz2
tar -jxf gmp-5.0.2.tar.bz2
mv gmp-5.0.2 gmp
mv gmp gcc-4.8.1
tar -xf mpc-0.9.tar.gz
mv mpc-0.9 mpc
mv mpc gcc-4.8.1
tar -jxf mpfr-2.4.2.tar.bz2
mv mpfr-2.4.2 mpfr
mv mpfr gcc-4.8.1
mkdir gcc-build-$TARGET
cd gcc-build-$TARGET
../gcc-4.8.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers
make -j 4 all-gcc
make install-gcc
make -j 4 all-target-libgcc
make install-target-libgcc
cd ..
EDIT UP : Just FYI.. You can see I am using the exact versions of all the files needed as you are.
Last edited by Kortath on Wed Sep 11, 2013 8:28 am, edited 2 times in total.
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

@ Sortie, I sent you a PM.

EDIT UPDATE : I just tried again but I substituted make -j 4 all with just make as sorties' tutorial suggests I use.

But I get the same error :
Makefile:841: recipe for target `all' failed
make: *** [all] Error 2
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by dozniak »

Just one note about the source.

In start.asm

Code: Select all

SECTION .text
Why do you have section .text directive AFTER the actual .text code? Afaik nasm defaults to .text section that's why it works, but it's clearly misplaced.

It would totally make sense to put the multiboot header into its own section though, so it doesn't get moved somewhere out of the first 8Kb once the kernel grows in size.

Give it own section and put it first in the linker.ld just before the (.text) section.
Learn to read.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by dozniak »

Kortath wrote: Makefile:841: recipe for target `all' failed
make: *** [all] Error 2
The actual error message is BEFORE that.
Learn to read.
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

dozniak wrote:Just one note about the source.

In start.asm

Code: Select all

SECTION .text
Why do you have section .text directive AFTER the actual .text code? Afaik nasm defaults to .text section that's why it works, but it's clearly misplaced.

It would totally make sense to put the multiboot header into its own section though, so it doesn't get moved somewhere out of the first 8Kb once the kernel grows in size.

Give it own section and put it first in the linker.ld just before the (.text) section.

So if I am understanding you correctly, it should be setup like this ? :

Code: Select all

global start
extern main

[BITS 32]

SECTION .text

start:
call main

cli
hlt

EXTERN code, bss, end

ALIGN 4
mboot:
   dd mboot
   dd code
   dd bss
   dd end
   dd start
dozniak wrote:
Kortath wrote: Makefile:841: recipe for target `all' failed
make: *** [all] Error 2
The actual error message is BEFORE that.
I'll retrace my steps and try to get the error message for you. Thanks.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by dozniak »

Kortath wrote:So if I am understanding you correctly, it should be setup like this ? :

Code: Select all

global start
extern main

[BITS 32]

start:
call main

cli
hlt

SECTION .text

EXTERN code, bss, end

ALIGN 4
mboot:
   dd mboot
   dd code
   dd bss
   dd end
   dd start
Not really, the actual code that you need to put in the .text section is still above the directive.

I would do it like this:

Code: Select all

global start
extern main

[BITS 32]
SECTION .text
; Here go the contents of the code section called .text

start:
call main

cli
hlt

SECTION .multiboot
; Here go the contents of the data section called multiboot

EXTERN code, bss, end

ALIGN 4
mboot:
   dd mboot
   dd code
   dd bss
   dd end
   dd start
Learn to read.
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

dozniak wrote:
Kortath wrote:So if I am understanding you correctly, it should be setup like this ? :

Code: Select all

global start
extern main

[BITS 32]

start:
call main

cli
hlt

SECTION .text

EXTERN code, bss, end

ALIGN 4
mboot:
   dd mboot
   dd code
   dd bss
   dd end
   dd start
Not really, the actual code that you need to put in the .text section is still above the directive.

I would do it like this:

Code: Select all

global start
extern main

[BITS 32]
SECTION .text
; Here go the contents of the code section called .text

start:
call main

cli
hlt

SECTION .multiboot
; Here go the contents of the data section called multiboot

EXTERN code, bss, end

ALIGN 4
mboot:
   dd mboot
   dd code
   dd bss
   dd end
   dd start

I would use this even if I am not using a multiboot ? I am not using Grub. I have my own Assembly two stage boot code that I have been working with.


On another note, here is a pastebin of everything I did up to the error using cygwin as gerryg400 suggested. Maybe you can spot the problem.

http://pastebin.com/raw.php?i=KDmpeekr
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by dozniak »

Kortath wrote:I would use this even if I am not using a multiboot ?
You don't need the multiboot header if you're not using multiboot. Is this just a blind copypaste?
Learn to read.
Kortath
Member
Member
Posts: 57
Joined: Sat Sep 07, 2013 11:23 am

Re: Windows 7 x64 ( Cross Compiler ) NO Libs

Post by Kortath »

dozniak wrote:
Kortath wrote:I would use this even if I am not using a multiboot ?
You don't need the multiboot header if you're not using multiboot. Is this just a blind copypaste?

Yes the whole thing is complete from start to finish. Every step from when I first start cygwin all the way to the error. As you can see, I am manually adding in each line.

EDIT UPDATE : So in actuality I don't need SECTION .text in there either then. I added it thinking it could help something. But I guess not. Keep in mind I have been studying the tutorials on the C and Assembly combination set-ups, and there are a lot of them. Most are outdated. And all of them are different from each other. So I was having to take a best guess at this part.

EDIT UPDATE 2 : Well I took SECTION .text out and sure enough it wasn't needed. It compiled with no errors when I used DJGPP.
Post Reply