This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: No loadable segment for a section with custom base address


I was not able to find an answer to my question (how to make a
loadable segment for a section with custom base address). Instead I
found other way to solve the problem and I want to share it, maybe
someone find it useful in the future.

Instead of relocating .smp.trampoline symbol addresses at link time,
we can do it at compile time. It is possible as we know the load
address during compilation (the address is 0x1000 in my case). Here is
the macro definition below. Every access to .smp.tramplone symbols
should be passed through RELOC() macro, like in this example:

#define SMP_AP_INIT_AREA 0x1000 // location where we load our 16bit code
#define RELOC(sym) ((sym) - smp_entry + SMP_AP_INIT_AREA)

  lgdt RELOC(smp.gdt.pointer)
  mov %cr0, %eax
  or $1, %eax # set BIT(0) to enable protected mode
  mov %eax, %cr0
  jmp $0x8, $(RELOC(protected_mode))


On Tue, Sep 26, 2017 at 10:56 AM, Anatol Pomozov
<> wrote:
> Hi
> My situation might be a bit unusual. I am trying to implement an SMP
> x86_64 OS. By default my .text area is loaded at 1M. And it works
> fine. Now I want to initialize SMP processors that start in real-time
> mode and can access memory only under 64K. I need to load a small init
> code to that lowmemory area (the init code switches to protected mode,
> does some basic initialization and then jumps to a C function in the
> main .text area). So my question is how to load a small part of text
> to low memory?
> Right now I have start_smp_trampoline.S. I want to compile this file
> with base address 40K. The only way to specify the base address I
> found is to create a separate ELF segment
>     .smp.trampoline 40K : {
>         __smp_trampoline_start = .;
>         KEEP(*(.smp.trampoline))
>         __smp_trampoline_end = .;
>     }
> It compiles and links fine. objdump shows addresses used in this
> trampoline segment are good. If linker created a segment loadable to
> 40K address and put my .smp.trampoline there it would probably solved
> my problem. But the linker does not add an additional loadable segment
> for it, hmm, why?
> If not adding a separate segment for .smp.trampoline section is
> intentional then I need to find another way to load my .smp.trampoline
> text to 40K address. I can do it in my OS code but I need to embed
> .smp.trampoline text to the main .text (or .rodata) section (the one
> loaded to 1M region), then find offset/size of the trampoline code.
> How to do that? Is there a way to embed a portion of text with a
> custom base address into another section that has different base
> address?
> Thanks for your help in advance.
> I use binutils 2.29.1 and gcc 7.2.0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]