Page 3 of 4
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 11:56 am
by Solar
As for the cross-compiler error, are you sure you used the command line options as described in the FAQ page? That looks like you forgot the --without-headers part... I don't have the Cygwin sources downloaded, but I'll try to verify later.
As for the global variables... are you sure your linker script / loader / whatever included your .data section? That's where global variables end up... (read, if you post your code, don't forget the linker script...)
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 12:09 pm
by srg
I'll try it again just in case
well, here is my linker script, it is modified from Tim's Mobius which was modified from cygwins linker script.
/*
* SG-OS kernel linker script: kernel.ld
* Modified from The Mobius kernel.ld
* Which was modified from Cygwin's i386pe.x
*/
OUTPUT_FORMAT(pei-i386)
SECTIONS
{
_scode = __image_base__;
.text __image_base__ + __section_alignment__ :
{
*(.init)
*(.text)
*(SORT(.text$*))
*(.glue_7t)
*(.glue_7)
___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
LONG (-1); *(.ctors); *(.ctor); LONG (0);
___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
LONG (-1); *(.dtors); *(.dtor); LONG (0);
*(.fini)
/* ??? Why is .gcc_exc here? */
*(.gcc_exc)
etext = .;
*(.gcc_except_table)
}
/* The Cygwin32 library uses a section to avoid copying certain data
on fork. This used to be named ".data". The linker used
to include this between __data_start__ and __data_end__, but that
breaks building the cygwin32 dll. Instead, we name the section
".data_cygwin_nocopy" and explictly include it after __data_end__. */
.data BLOCK(__section_alignment__) :
{
__data_start__ = . ;
*(.data)
*(.data2)
*(SORT(.data$*))
__data_end__ = . ;
*(.data_cygwin_nocopy)
}
.rdata BLOCK(__section_alignment__) :
{
*(.rdata)
*(SORT(.rdata$*))
*(.eh_frame)
}
.pdata BLOCK(__section_alignment__) :
{
*(.pdata)
}
.edata BLOCK(__section_alignment__) :
{
*(.edata)
}
/DISCARD/ :
{
*(.debug$S)
*(.debug$T)
*(.debug$F)
*(.drectve)
}
/*
* SG-OS kernel: The kernel doesn't import anything.
* We save 4096 bytes by omitting these five zeroes.
*/
.idata BLOCK(__section_alignment__) :
{
/* This cannot currently be handled with grouped sections.
See pe.em:sort_sections. */
SORT(*)(.idata$2)
SORT(*)(.idata$3)
/* These zeroes mark the end of the import list. */
LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
SORT(*)(.idata$4)
SORT(*)(.idata$5)
SORT(*)(.idata$6)
SORT(*)(.idata$7)
}
.CRT BLOCK(__section_alignment__) :
{
*(SORT(.CRT$*))
}
.endjunk BLOCK(__section_alignment__) :
{
/* end is deprecated, don't use it */
end = .;
_end = .;
__end__ = .;
_edata = .;
}
.rsrc BLOCK(__section_alignment__) :
{
*(.rsrc)
*(SORT(.rsrc$*))
}
.reloc BLOCK(__section_alignment__) :
{
*(.reloc)
}
.stab BLOCK(__section_alignment__) (NOLOAD) :
{
[ .stab ]
}
.stabstr BLOCK(__section_alignment__) (NOLOAD) :
{
[ .stabstr ]
}
.bss BLOCK(__section_alignment__) :
{
__bss_start__ = . ;
_sbss = .;
/*
* Added stack and kernel page directory.
* These are in the linker script to ensure alignment and size:
* it is vital that the page directory be page-aligned.
*/
_stack = .;
. += 8192;
_stack_end = .;
_kernel_stack_end = .;
_arch_df_stack = .;
. += 4096;
. = ALIGN(4096);
_kernel_pagedir = .;
. += 4096;
*(.bss)
*(COMMON)
. = ALIGN(4096);
_ebss = .;
__bss_end__ = . ;
}
}
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 12:23 pm
by srg
I definatly did enter the command line for the cross compiler as said in the FAQ, except I used i386-elf.
BTW, would a linker script for an elf kernel be a lot simpler that the standard cygwin based thing I have above??
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 12:29 pm
by Solar
*rollingonthefloorlaughing*
Here's the one I use with my Cygwin-based cross-compiler - although I have to admit that my kernel does preciously little ATM (read, the linker script might grow):
Code: Select all
ENTRY (kernel_loader)
SECTIONS
{
. = 0x00100000;
.text :
{
*(.text)
*(.rodata)
}
.data ALIGN (0x1000) :
{
start_ctors = .;
*(.ctor*)
end_ctors = .;
*(.data)
}
.bss :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
}
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 12:42 pm
by srg
there's not much I can say to that heh
what is .ctor BTW
Oh yes, Lets get that cross compiler working!!
Could the trouble be because I'm using the source that came with cygwin.
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 1:10 pm
by Solar
srg wrote:
what is .ctor BTW
I'm using C++ as language. .ctor* is a list of pointers pointing to the constructors of global / static data objects, which I have to call from my assembly bootstrap code before I can use them in my C++ main().
Could the trouble be because I'm using the source that came with cygwin.
That's possible; I've never tried the Cygwin source.
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 2:12 pm
by srg
Right I've just tried to compile a cross compiler with downloaded (non cygwin) sources and I get exactly the same error!!!!
Is there anything that I sould or shouldn't install when I install cygwin??
Re:Grub and PE based Kernels
Posted: Wed Feb 18, 2004 11:50 pm
by Solar
Please give more information, as I am unable to reproduce the error:
* what version of binutils and gcc are you using? (Version used for building, and version of the sources to be build)
* which commands have you used to compile the stuff? Exactly as in the tutorial, or did you omit / change / add some options?
I really want that tutorial to be correct...
Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 2:17 am
by srg
Sure, I also want a cross compiler
I'm building with gcc version 3.3.1 (cygming special)
and binutils 2.14.90 20030901
The sources I'm using are: gcc version 3.3.1 and binutils-2.14 (downloaded seperately)
The only thing on the command line that I have changed is the TARGET, I'm using i386-elf.
BUT I have tried i586-elf and I get the same error!
BTW The last time I tried to make a cross compiler, I gave up after over a week of trying.
Please could you give me a list of all the packages that you install when installing cygwin, as that could be that cause of the problem. Maybe I'm missing one?
Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 6:58 am
by Solar
D'oh... I got the same error with the 3.3.1 sources - the 3.3 sources worked fine. :-\
Oh, how I love the stability of the Open Source...

Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 7:55 am
by Pype.Clicker
@solar: and i'm still sticking on gcc-2.95.3 for that kind of reasons ;-P
Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 8:54 am
by Solar
...basically a non-option if you're after C++ - much too much improved from 2.95 -> 3.3...
Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 9:28 am
by Solar
Damnit, looks like I have used --with-newlib when configuring my cross-gcc, but didn't state so in the Wiki page.
I don't have time left to verify this today; maybe you can try it, srg?
Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 9:37 am
by srg
Solar wrote:
Damnit, looks like I have used --with-newlib when configuring my cross-gcc, but didn't state so in the Wiki page.
I don't have time left to verify this today; maybe you can try it, srg?
Will do
Actually, I've seen on a site showing how to make a sparc cross compiler they used this --with-newlib switch
what is newlib?
Anyway, about to test
Re:Grub and PE based Kernels
Posted: Thu Feb 19, 2004 9:44 am
by nullify
Building a cross-compiled version of GCC 3.3.1 as per your instructions worked without any problems for me...
Code: Select all
$ i686-elf-gcc --version
i686-elf-gcc (GCC) 3.3.1 (cygming special)
Copyright (C) 2003 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.
It might not be entirely related to the version of GCC.