Page 6 of 6
Re: Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Wed Sep 11, 2013 3:05 pm
by Kortath
gerryg400 wrote:Kortath, do you have g++ installed in Cygwin ? What happens if you type g++ from your Cygwin command line ?
the wiki page on Cross Compiling wrote:C++ preprocessor "/lib/cpp" fails sanity check in Cygwin when building Binutils
In Cygwin's installer, you need to separately select the gcc4-core and gcc4-g++ packages for proper configuration of the host compiler.
WOW. bad command. .sweet. I'll install it now and see what happens. I'll report back once I'm done.
EDIT UPDATE : Well so far its still going.. that's a good sign. I have three more commands to go from that script and its done. Just 3 more.. Come on BABY YOU CAN DO IT !!!
Done :
$ gcc --version
gcc (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
OMG.. This was a LOT of work. Thank you guys. Now I can finally go try to compile my OS...
Re: Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Wed Sep 11, 2013 4:11 pm
by Kortath
You guys ROCK !!!!
Isn't this a pretty site !!!
File size of the kernel file is 469 Bytes.
My batch file I used :
compile.bat
Code: Select all
yasm -f elf -o start.o start.asm
i586-elf-gcc -ffreestanding -c -o kernel.o kernel.c
i586-elf-ld -T linker.ld --oformat binary -o kernel32.sys start.o kernel.o
pause
start.asm
Code: Select all
global start
extern main
[BITS 32]
start:
call main
cli
hlt
EXTERN code, bss, end
ALIGN 4
mboot:
dd mboot
dd code
dd bss
dd end
dd start
linker.ld
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) }
}
start.sh for cygwin :
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 --prefix=$PREFIX --target=$TARGET --program-prefix=$TARGET- --disable-werror --enable-gold --enable-plugins --disable-nls --disable-shared --disable-multilib
make -j 1 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 1 all-gcc
make install-gcc
make -j 1 all-target-libgcc
make install-target-libgcc
Cygwin needed these libraries :
diff, bison, flex, m4, g++, make
I also used the following versions for this compile :
binutils-2.23.1.tar.bz2
gcc-4.8.1.tar.bz2
gmp-5.0.2.tar.bz2
mpc-0.9.tar.gz
mpfr-2.4.2.tar.bz2
This batch file I tested it with YASM. It works just like NASM.
I owe the following people a HUGE thank you for the knowledge they have shown and their patience in helping me understand what to do.
gerryg400
dozniak
sortie
piranha
halofreak1990
AJ
Combuster
Owen
beyondsociety
I am most humbled by this experience. THANK YOU !!!!!
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Wed Sep 11, 2013 10:27 pm
by dozniak
Well spotted, gerryg400!
Kortath, if you read these forums more than you'll see there's very low tolerance level towards blindly "assuming" anything. That's why me and Combuster recommend you to have the "section .text" directive anyway. This way you exactly know where nasm/yasm will place your code, without assuming anything. And in the unlikely case the default section name changes in any of those assemblers you'll save yourself a lot of frustrating debugging time.
The section directive should go BEFORE the section it so declares. I recommend you spend little but very valuable time reading the nasm manual.
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 5:11 am
by Kortath
dozniak wrote:Well spotted, gerryg400!
Kortath, if you read these forums more than you'll see there's very low tolerance level towards blindly "assuming" anything. That's why me and Combuster recommend you to have the "section .text" directive anyway. This way you exactly know where nasm/yasm will place your code, without assuming anything. And in the unlikely case the default section name changes in any of those assemblers you'll save yourself a lot of frustrating debugging time.
The section directive should go BEFORE the section it so declares. I recommend you spend little but very valuable time reading the nasm manual.
Most definitely will look into that. Thanks for the info.
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 8:52 am
by Kortath
I read this topic here : 6.3 SECTION or SEGMENT: Changing and Defining Sections
http://www.nasm.us/doc/nasmdoc6.html
Which eventually pointed me here :
7.1.3 Multisection Support for the bin Format
http://www.nasm.us/doc/nasmdoc7.html#section-7.1.3
EDIT UPDATE : I just checked out this OSdev tut.. it shows this :
http://www.osdev.org/howtos/1/
If you noticed I moved this :
EXTERN code, bss, end
My understanding is that this is required before I put the
SECTION .text in.
Code: Select all
[BITS 32]
GLOBAL _sayhi
GLOBAL _quit
SECTION .text
_sayhi: mov byte [es:0xb8f9c],'H'
mov byte [es:0xb8f9e],'i'
ret
_quit: mov esp,ebp
pop ebp
retf
So according to that, I should be writing mine like this ...
Code: Select all
[BITS 32]
GLOBAL start
EXTERN main ,code, bss, end
SECTION .text
start:
call main
cli
hlt
If I am understanding this correctly, I removed the following code. ALIGN is taken care of in my linker.ld script. And I'm not multibooting. ( And not using GRUB )
Code: Select all
ALIGN 4
mboot:
dd mboot
dd code
dd bss
dd end
dd start
EDIT UPDATE 2 : OK I compiled with it this way and my resulting kernel file ended up even smaller. 449 Bytes. SWEET !
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 11:18 am
by dozniak
The align directive was to align the following multiboot header to dword boundary, as required by the multiboot standard. Linker script has nothing to do with this.
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 11:25 am
by Combuster
I removed the following code.
(...)
I'm not multibooting.
Then what will be your bootloader?
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 11:49 am
by Kortath
dozniak wrote:The align directive was to align the following multiboot header to dword boundary, as required by the multiboot standard. Linker script has nothing to do with this.
OK so put it back then.. in that same place Like This ?
Code: Select all
[BITS 32]
GLOBAL start
EXTERN main ,code, bss, end
SECTION .text
start:
call main
cli
hlt
ALIGN 4
mboot:
dd mboot
dd code
dd bss
dd end
dd start
Combuster wrote:I removed the following code.
(...)
I'm not multibooting.
Then what will be your bootloader?
I have my own source ( Using YASM / NASM ) code for my own bootloader.
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 11:59 am
by dozniak
Kortath wrote:dozniak wrote:The align directive was to align the following multiboot header to dword boundary, as required by the multiboot standard. Linker script has nothing to do with this.
OK so put it back then.. in that same place Like This ?
If you don't do multiboot, you don't need neither multiboot header nor the align directive.
Re: [ Solved ] Windows 7 x64 ( Cross Compiler ) NO Libs
Posted: Thu Sep 12, 2013 12:10 pm
by Kortath
dozniak wrote:Kortath wrote:dozniak wrote:The align directive was to align the following multiboot header to dword boundary, as required by the multiboot standard. Linker script has nothing to do with this.
OK so put it back then.. in that same place Like This ?
If you don't do multiboot, you don't need neither multiboot header nor the align directive.
OK that makes more sense. So if someone was to use my project ( code, linker, batch ) they might want to add that in there if they use GRUB or their own multiboot loader. Cool.