[SOLVED] Use ld to output flat binary for real mode

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.
Post Reply
person4268
Posts: 3
Joined: Sun Jul 22, 2018 12:07 am
Libera.chat IRC: person4268

[SOLVED] Use ld to output flat binary for real mode

Post by person4268 »

I basically want to use ld to output as a flat binary that I can use in real mode. I mostly want to do this so that I can use C for my second stage bootloader. Here is my linker script heavily based off of(mostly copied) it's page on the OsDev Wiki:

Code: Select all

ENTRY(start)
STARTUP(bootldr_s2.s.o)
OUTPUT_FORMAT("binary_i386?") /* Biggest isue here */ 
SECTIONS
{
  .text.start (_KERNEL_BASE_) : { /* I change this to 0x0000, right? */
    bootldr_s2.s.o( .text )
  }

  .text : ALIGN(0x1000) {
_TEXT_START_ = .;
    *(.text)
_TEXT_END_ = .;
  }

  .data : ALIGN(0x1000) {
_DATA_START_ = .;
    *(.data)
_DATA_END_ = .;
  }

  .bss : ALIGN(0x1000) {
_BSS_START_ = .;
    *(.bss)
_BSS_END_ = .;
  }


}
My biggest issue here is that I don't know what I should put as the output format. If i use "binary", it gives me this:

Code: Select all

ld: skipping incompatible bootldr_s2.s.o when searching for bootldr_s2.s.o
ld: cannot find bootldr_s2.s.o
Note that bootldr_s2.s was compiled with

Code: Select all

nasm -f elf -o bootldr_s2.s.o
and that it's currently

Code: Select all

    BITS 16
    start:
        mov eax, 0xBCAF ;If this is in eax, then the code loaded
        jmp $
I'm not really sure where to go from here, and would really appreciate some help.
Last edited by person4268 on Sun Jul 22, 2018 7:46 am, edited 1 time in total.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Use ld to output flat binary for real mode

Post by alexfru »

Check out Smaller C.
GeGuNa
Posts: 12
Joined: Sun Apr 02, 2017 11:43 am

Re: Use ld to output flat binary for real mode

Post by GeGuNa »

ENTRY(start)
STARTUP(bootldr_s2.s.o) // set startup file (bootldr_s2.s.o)
OUTPUT_ARCH(i386) // set arch = i386 (32 bit ) / or i386:x86-64 (64 bit) / ia64 (for ia 64 arch)
OUTPUT_FORMAT("binary") // set output type (elf32-i386 / elf32-x86-64 / elf64-x86-64 / pe-i386 / pe-x86-64 / binary )
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Use ld to output flat binary for real mode

Post by iansjack »

If you have a single input file, and want bin format output, why are you using elf files and the linker? Nasm can output a bin file directly.
person4268
Posts: 3
Joined: Sun Jul 22, 2018 12:07 am
Libera.chat IRC: person4268

Re: Use ld to output flat binary for real mode

Post by person4268 »

I know that nasm can output a flat binary file, but I'm linking so that I can use C once I get this working.
person4268
Posts: 3
Joined: Sun Jul 22, 2018 12:07 am
Libera.chat IRC: person4268

Re: Use ld to output flat binary for real mode

Post by person4268 »

I should also mention that GeGuNa's answer worked. Thanks for all the help!
Post Reply