Grub and PE based Kernels

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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post 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...)
Every good solution is obvious once you've found it.
srg

Re:Grub and PE based Kernels

Post 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__ = . ;
}
}
srg

Re:Grub and PE based Kernels

Post 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??
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post 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 = .;
    }
}
Every good solution is obvious once you've found it.
srg

Re:Grub and PE based Kernels

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post 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.
Every good solution is obvious once you've found it.
srg

Re:Grub and PE based Kernels

Post 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??
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post 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...
Every good solution is obvious once you've found it.
srg

Re:Grub and PE based Kernels

Post 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?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post 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... :P
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Grub and PE based Kernels

Post by Pype.Clicker »

@solar: and i'm still sticking on gcc-2.95.3 for that kind of reasons ;-P
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post by Solar »

...basically a non-option if you're after C++ - much too much improved from 2.95 -> 3.3...
Every good solution is obvious once you've found it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Grub and PE based Kernels

Post 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?
Every good solution is obvious once you've found it.
srg

Re:Grub and PE based Kernels

Post 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
nullify

Re:Grub and PE based Kernels

Post 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.
Post Reply