Page 1 of 1

OS - Cross Compiler - Assembly

Posted: Sun Aug 21, 2016 11:18 am
by Chpetrou
Hello

I want to learn how to create my own Operating System and i saw the bare bones guide, and it was required to build your own GCC Cross Compiler, but the instructions on http://wiki.osdev.org/GCC_Cross-Compiler aren't so clear for me and i can't make it work.

I have a Mac - OS X and have installed the GCC and the other software required through homebrew. I also know the basics of C, C++, Java and 5 other languages and i know Java, C++ at a more advanced level. I am also trying to learn Assembly with nasm and i think i know most of the Computer Theory.

Can you help me?

Also is this (bare bones) the best way to learn how to create a functional OS from scratch?

Also do you know a good way to learn Assembly, because i can't find very much resources to solve my questions?

Thanks in advance

Re: OS - Cross Compiler - Assembly

Posted: Sun Aug 21, 2016 12:21 pm
by max
Hey,

welcome to the forum!
Chpetrou wrote:[...] the instructions on http://wiki.osdev.org/GCC_Cross-Compiler aren't so clear for me and i can't make it work. [...] Can you help me?
What is unclear? What did you try and where did you fail?
Chpetrou wrote:Also is this (bare bones) the best way to learn how to create a functional OS from scratch?
There's no "best way", and it's a long way to have something functional. But it's a good starting point.
Chpetrou wrote:Also do you know a good way to learn Assembly, because i can't find very much resources to solve my questions?
Use Google.

Greets

Re: OS - Cross Compiler - Assembly

Posted: Sun Aug 21, 2016 12:37 pm
by Chpetrou
Hello

Generally i get confused with the instructions of how to make the i686-elf cross compiler. I tried

Code: Select all

cd $HOME/src
mkdir build-binutils
cd build-binutils
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
and it doesn't work because i don't have a $HOME/src (so I created an src directory in the usr/local) and i don't can't make

Code: Select all

../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
to work because i don't know what it is (i don't understand the "../binutils-x.y.z/configure" part).

Also doing the steps above this is the same by installing the required software through homebrew right? or do i have to do something else before?

Re: OS - Cross Compiler - Assembly

Posted: Sun Aug 21, 2016 1:19 pm
by Roman
binutils-x.y.z is the source directory you've unpacked.

Re: OS - Cross Compiler - Assembly

Posted: Sun Aug 21, 2016 2:20 pm
by Chpetrou
What do you mean by "source directory you've unpacked"?

I installed the software through homebrew. Should i have done it differently?

Re: OS - Cross Compiler - Assembly

Posted: Sun Aug 21, 2016 3:23 pm
by Roman
What and how you installed via Homebrew?

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 12:14 am
by Chpetrou
I wrote in the Terminal

Code: Select all

brew install gcc
and it installed the latest gcc, gmp, gpfr, isl, mpc, textinfo and also installed binutils, libiconv and xcode clt

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 1:57 am
by iansjack
I'm not convinced that you understand why you should install a cross-compiler. Two important reasons are:

1. You want to generate code for your target processor. This may not be the same processor that your computer uses. For example, OS X uses the x86_64 processor, whereas you probably want to generate code for the 32-bit x86 processor. The compiler you have installed will be aimed at producing 64-bit programs.

2. You want to generate code that does not rely upon the OS running on your development computer.

The compiler that you have installed does not satisfy either of these conditions. The instructions on the Wiki only mention using homebrew if you are running OS X 10.7 or earlier. Is that your situation?

Read the instructions again carefully and follow them exactly.

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 2:43 am
by Octacone
Just replace x.y.z with your version numbers.

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 3:42 am
by Chpetrou
1. Isn't the GCC installed from homebrew the same as downloading from its official website? Can't we build the gcc installed from homebrew to a 32 bit one ? with the

Code: Select all

export TARGET=i686-elf
instruction? I mean, Build (ex. a program), is to take the source code and compile it with our processor to create an executable file that we can use, but that doesn't make the executable run only on the same processor architecture that was compiled?

2. So if i have understood well, up to the preparing for the build section, i only have to download the required software from the pages given? I have downloaded the software, extracted it from the .tar.bz2 and now i have the folders with the files inside, in my documents folder.

Also do i need to do these:

Code: Select all

../binutils-2.24/configure --prefix=$PREFIX \
--target=$TARGET \
--enable-interwork --enable-multilib \
--disable-nls --disable-werror
../gcc-4.8.3/configure --prefix=$PREFIX \
--target=$TARGET \
--disable-nls \
--enable-languages=c,c++ --without-headers \
--enable-interwork --enable-multilib \
--with-gmp=/usr --with-mpc=/opt/local --with-mpfr=/opt/local
because they don't work because of "../binutils-2.24/configure"

But on the Build section, i do

Code: Select all

export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
successfully but on the

Code: Select all

cd $HOME/src
 
mkdir build-binutils
cd build-binutils
../binutils-x.y.z/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
it doesn't accept it. Even if i write the version in "binutils-x.y.z", it says there is no such directory "../binutils-x.y.z/configure"

Is ".." like cd .. that takes you backwords? or it is the folder that the binutils-x.y.z is inside?

i tried it also from the binutils folder.

Also there is no "configure" in the folder.

Sorry for not understanding, i have a difficulty at understanding things that are not too explained for me. I work better with videos and pictures but there are not usually videos and pictures for such things.

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 3:53 am
by Roman
Isn't the GCC installed from homebrew the same as downloading from its official website?
No.

Code: Select all

$ /usr/local/bin/gcc-4.9 -dumpmachine
x86_64-apple-darwin16.0.0
$ x86_64-w64-mingw32-gcc -dumpmachine
x86_64-w64-mingw32
$ arm-none-eabi-gcc -dumpmachine
arm-none-eabi

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 4:22 am
by gerryg400
I fear that if you are at the point where you are not sure what '..' means you may not be ready to write an operating system.

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 5:10 am
by Chpetrou
I though about these in a different way and tried a few things and i found it, and i made it work.

Thanks for all the answers.

Re: OS - Cross Compiler - Assembly

Posted: Mon Aug 22, 2016 4:43 pm
by Schol-R-LEA
I realize that you said you have solved the issues, but I did want to explain two things you seemed unclear on.

First, the '.' and '..' entries in the directory are hidden hard links to the directory itself ('.') and its parent directory ('..'). They are actual directory entries automatically inserted into every Unix directory when it is created, as can be seen if you do a directory listing with the display hidden files option ('-a', for 'all'):

Code: Select all

ls -a
Second, $HOME is a common (but not quite universal) environment variable usually set in most Bourne-Again Shell (bash, which is a modified version of the original Bourne Shell, sh) environments in the .bashrc and/or .bash-profile scripts; Bourne-style environment variables start with a dollar sign, and are by convention written in ALL-CAPS. The usual practice is for $HOME to be an alias for the user's home directory, equivalent to '~', so if your user name is 'joeblow', then

Code: Select all

cd ~
cd $HOME
cd /home/joeblow
would in most cases go to the same directory path.

Now the tutorial is written with the assumption that you are using Bash, because that's the most widely used shell in the Linux world and the default for Debian (and derivatives like Ubuntu, Mint, etc.), Gentoo, and several others, including recent versions of Mac OS X - though earlier versions (Tiger and before) used tsch instead, and I'm pretty sure both tsch, zsh, Korn Shell (ksh) are still installed by default if you want to change it. You really need to learn Bash (and Unix in general) to use the tutorial effectively, but tutorials on Bash are easy enough to come by, even if they aren't all necessarily all that good.

On the subject of tutorials, you have to also keep in mind that the Bare Bones tutorials are not intended to give you a full system, or even a working one; they are a starting point for understanding what's involved. No tutorial out there explains how to actually write an operating system, and none ever could.