grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PowerPC C++ kernel woes.


From: Andrei Warkentin
Subject: Re: PowerPC C++ kernel woes.
Date: Sun, 27 Nov 2005 03:05:26 -0600

Hello,

I would just like to provide an update and re-cast some of my questions. I've tried doing various things, and initially I put sbss/ sdata in different sections, however I kept getting CLAIM failed while trying to boot the file. I later completely rewrote my linker script (which I'll paste at the end of this email), sticking in sbss {1,2} into the bss section, and sdata{1,2} into data section, during which I found out I forgot about .gnu.linkonce.sb. The file loaded and worked just fine after that, and I presume it was because of the now non-missing .gnu.linkonce.sb and not because of I coalesced the sdata/sbss sections. Somewhere in the last 6 hours I've even tried converting to XCOFF (using objcopy), but I would get "bad omagic" from OF.

So now that works, which is good :). But what about _SDA_BASE_ and SDA_BASE2_? The linker sticks these at the very end. If I disassemble my kernel, I don't see any references to r13, r14 or _SDA_BASE_/ _SDA_BASE2_. Do I need to care about these? Somehow it seems the small data/bss can be accessed without these, which seems to contradict what I've gathered from the PowerPC EABI document. Hmmm.

I've examined the build instructions for GRUB2 (under conf/), and nothing special appears to be done aside from linking at 2MB (that is, no handling of SDA_BASE-stuff). AFAIK, some default ld-script is used while building GRUB2. Am I correct? Is this the standard ld- script used to be exec-objects under PPCLinux?

My other question is one of alignment. Looking at various PPC-related ld-scripts I found through Google, a lot seem concerned with aligning data/bss by 4 bytes or by 8. Is there any reason for this? AFAIK, the default linux one does not care about alignment a whole lot. As far as I understand, PPC can cope with misaligned data in hardware. I know that, on the x86 some cpu structures (like the GDT) have to be aligned...

Thanks again for all of your help. I'm attaching my current ld script in case someone is interested.

/*
   Output will be an ELF file, that can be
   loaded by OpenFirmware 3.0 on a PowerMac.
*/
OUTPUT_FORMAT("elf32-powerpc")

/* Defined in head.cpp */
ENTRY(ld_start)
SECTIONS
{

/* Kernel will be linked at 2MB. */
. = 0x200000;

/* The text section is already page
    aligned since 2MB is page aligned.
*/
.text : {

  /* Symbols to mark start of section. */
  ld_text = .;

  /* Code. */
  *(.text)
  *(.text.*)

  /* C++ templates/vtables. */
  *(.gnu.linkonce.t.*)

  /* Read-only data (ELF only). */
  *(.rodata)
  *(.rodata.*)
  *(.gnu.linkonce.r.*)
/* C++ global/static constructors. */
  ld_text_ctors = .;
  *(SORT(.ctor*))
  ld_text_ctors_end = .;

  /* C++ global/static destructors. */
  ld_text_dtors = .;
  *(SORT(.dtor*))
  ld_text_dtors_end = .;

  /* End. */
  ld_text_end = .;
}

/* The data section. */
.data : {
  ld_data = .;

  /* Data. */
  *(.data)
  *(.data.*)
  *(.gnu.linkonce.d.*)

  /* Small data. */
  *(.sdata)
  *(.sdata.*)
  *(.gnu.linkonce.s.*)

  /* Small data 2. */
  *(.sdata2)
  *(.sdata2.*)
  *(.gnu.linkonce.s2.*)
  ld_data_end = .;
}

/* The BSS section. */
.bss : {
  ld_bss = .;

  /* BSS. */
  *(.bss)
  *(.bss.*)
  *(.gnu.linkonce.b.*)

  /* SBSS. */
  *(.sbss)
  *(.sbss.*)
  *(.scommon)
  *(.gnu.linkonce.sb.*)

  /* SBSS2. */
  *(.sbss2)
  *(.sbss2.*)
  *(.gnu.linkonce.sb2.*)

  /* "common" variables. */
  *(COMMON)
  ld_bss_end = .;
}

/* The stack section. */
.stack : {
  ld_stack = .;

  /* Stack will be 16K */
  . = ld_stack + 0x4000;
  ld_stack_end = .;
}
ld_end = .;
}


On Nov 26, 2005, at 6:42 PM, Andrei Warkentin wrote:

Hello,

I've been trying to get some C++ running (now that I can print "Hello World" from OF, I'd like to move my "Hello World" C++ kernel to PowerPC), but it has been without much success. I've finally figured out that there are these small data sections which I was not taking care of in my ld script (sdata, sbss, sdata2, sbss2). Prior to me figuring this out, I would get a crash. After I added these sections, I've noticed several globals appear in .sbss (using powerpc-linux-nm to see all syms), but now I get CLAIM failed while loading my kernel in OF. Odd.

So I guess I have several questions:
Am I doing something wrong w.r.t sdata, sbss, sbss2, and sdata2 in my ld script? I am also not sure as to how these should be aligned, if at all. What about _SDA_BASE_ and _SDA_BASE2_? AFAIK, these should point in the middle of the sdata+sbss and sdata2+sbss2. Should I load r13 and r14 with these values?
   So far my code doesn't appear to use either register.

I 've been doing this for SDA_BASE and SDA2_BASE
 PROVIDE (_SDA_BASE_ = ld_sdata + ((ld_sbss_end - ld_sdata) / 2));
 PROVIDE (_SDA2_BASE_ = ld_sdata2 + ((ld_sbss2_end - ld_sdata2) / 2));

... but the linker seems to ignore my values and gives
 0020f000 G _SDA_BASE_
00210000 G _SDA2_BASE_
( kernel linked @ 2MB, same way as I linked my C hello world example, which works just fine).

Thanks and have a great day.

/* The sdata section. */
.sdata ALIGN(0x1000): {
  ld_sdata = .;

  /* SData. */
  *(.sdata)
  *(.gnu.linkonce.s.*)
  ld_sdata_end = .;
}

.sbss : {
  ld_sbss = .;

  /* BSS. */
  *(.sbss)
  *(.scommon)
  ld_sbss_end = .;
}

/* The sdata2 section. */
.sdata2 ALIGN(0x1000): {
  ld_sdata2 = .;

  /* SData2. */
  *(.sdata2)
  *(.gnu.linkonce.s2.*)
  ld_sdata2_end = .;
}

/* The SBSS2 section. */
.sbss2 : {
  ld_sbss2 = .;

  /* SBSS2. */
  *(.sbss2)
  *(.gnu.linkonce.sb2.*)
  ld_sbss2_end = .;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]