Problem in using cross compiler.

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
piyushneo
Posts: 5
Joined: Thu Jan 13, 2011 3:01 am

Problem in using cross compiler.

Post by piyushneo »

I am following the OS development tutorial at http://www.brokenthorn.com/Resources/OSDevIndex.html . After completing bootloader they have used MS Visual C++ to develp kernal further and given instruction to setup Runtime Environment for the same. But i am working on a Linux Platform ( Ubutnu) and will be using gcc for my kernal development. I read a great article about GCC Cross-compiler http://wiki.osdev.org/GCC_Cross-Compiler on this site which seems to be solution for my problem but i have few doubts regarding that :
1. Do i have to build cross compiler up to stage 1 or 2 ?
2. Will the binary generated be a flat binary i.e i need not to parse the kernal file in order to get the entry point , just start executing with the first byte of file.
3. As kernel is loaded at 0x00100000. How to set base address with this cross compiler?
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Problem in using cross compiler.

Post by Tosi »

piyushneo wrote: 1. Do i have to build cross compiler up to stage 1 or 2 ?
I have no idea what this means. I would say no.
2. Will the binary generated be a flat binary i.e i need not to parse the kernal file in order to get the entry point , just start executing with the first byte of file.
You can tell the linker whether to generate a flat binary or an actual executable format. I do not recommend making a flat binary kernel.
3. As kernel is loaded at 0x00100000. How to set base address with this cross compiler?
Use a linker script to lay out your sections. You can tell it what the physical and virtual addresses are for each section.
piyushneo
Posts: 5
Joined: Thu Jan 13, 2011 3:01 am

Re: Problem in using cross compiler.

Post by piyushneo »

1. Do i have to build cross compiler up to stage 1 or 2 ?
Sorry a typo..i meant step 1 or 2 ( given on link above)...though i knew its answer now.
Use a linker script to lay out your sections. You can tell it what the physical and virtual addresses are for each section.
When i will compile through cross compiler, will the section term still be valid as it is no more efl ? i mean can i use the same script which is used for elf format?
Thanks for replying..
Graham
Posts: 14
Joined: Thu Mar 04, 2010 7:29 am
Location: UK
Contact:

Re: Problem in using cross compiler.

Post by Graham »

piyushneo wrote:
Use a linker script to lay out your sections. You can tell it what the physical and virtual addresses are for each section.
When i will compile through cross compiler, will the section term still be valid as it is no more efl ?
If I recall correctly the tutorial in the wiki shows you how to build a cross compiler which will output 32-bit ELF files.

I just use gcc/clang and ld from the Ubuntu repositories and set the appropriate flags (-m32 and -ffreestanding for the C compiler and -melf_i386 for ld) to make them produce 32 bit code without relying on the host operating system's libraries, which seems to be working fine and avoids all the hassle :p.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Problem in using cross compiler.

Post by Combuster »

If you use the host compiler, you can still drag in linux-specific code. The arguments will not prevent such errors. Also, the arguments look like they expect an amd64 toolchain - it might not work on 32-bit linux, it will not work if you have an relatively old version of gcc, it will not work under windows, and it will not work on non-intel platforms. I won't start about clang/llvm as it can be rather unfriendly to anyone trying to get one to work.

In any case, the cross-compiler requires no arguments that you can forget, will never drag in references to your host unless you explicitly tell it to, and will work the same on any platform.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply