User:AlfaOmega08/Cygwin toolchain

From OSDev Wiki
Jump to: navigation, search

Here, I'm going to explain how to create a toolchain on cygwin to be used to create and run x86-64-elf kernels on Windows. I'm mainly using this page to not forget the steps I've done.

Contents

Needed packages

Open cygwin's setup.exe and install:

  1. gcc
  2. gcc-g++
  3. flex
  4. bison
  5. nasm
  6. make
  7. automake
  8. autoconf
  9. libiconv
  10. libmpfr-dev
  11. libmpc-dev
  12. libgmp3-dev

Something more might be needed. I may expand the list.

The cross compiler

First of all you need a compiler. See GCC Cross Compiler. Or download gcc-4.7.0.tar.bz2 and binutils-2.22.tar.bz2 and use the following commands:

tar xvf gcc*
tar xvf binutils*
mkdir build-{binutils,gcc}

First install binutils:

cd build-binutils
../binutils*/configure --target=x86_64-elf --prefix=/usr/cross64 --disable-nls
make all -j <# of cores on your proc * 2>
make install
cd ..

Then gcc:

export PATH=$PATH:/usr/cross64/bin
cd build-gcc
../gcc*/configure --target=x86_64-elf --prefix=/usr/cross64 --enable-languages=c,c++ --disable-nls
make all-gcc -j <# of cores * 2>
make install-gcc
make all-target-libgcc -j <# * 2>
make install-target-libgcc

GRUB2

The "stable" version of GRUB2 is bugged. It can't boot elf64 properly. So download the latest grub release here. Extract the package and edit /grub-core/loader/multiboot-elfxx.c, by adding

# define Elf_Shdr	Elf32_Shdr

at line 25 and:

# define Elf_Shdr	Elf64_Shdr

at line 32

Now open cygwin and run:

cd grub*
./configure

The gcc version that comes with cygwin is very old and misses some flags of GRUB2 setup so open ./Makefile and ./grub-core/Makefile and remove all references to: "-Werror" and "-Wmissing-field-initializers" and don't touch anything else. Now you can:

make all -j <# * 2>
make install

xorriso

The tool I use to make iso image with GRUB2 (grub-mkrescue) needs xorriso which isn't shipped with cygwin. Download the latest release here and then:

tar xvf xorriso*
cd xorriso*
./configure
make all -j <# * 2>
make install

This needs libiconv (or libiconv-dev?)

Now you should be able to compile & link a 64 bit kernel using /usr/cross64/bin/x86_64-elf-{gcc,g++,ld,objdump,whatever} and the version of nasm which comes packed with cygwin, and to create a (working) boot iso using:

grub-mkrescue --output=image.iso iso

GDB

So you wan't to use GDB to debug your OS? That's a PITA. It took me a lot to find the right combination of commands to create a decent GDB on cygwin. So download the latest GDB snapshot and compile it like this:

./configure --host=i686-pc-cygwin --target=x86_64-unknown-linux-gnu
make all -j <you know what>
make install

It seems that x86_64-unknown-linux-gnu is the most similar to x86_64-elf that will accept to work with gdb.

Have a good time OSDeving.

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox